Exercises
The following exercises cover the various topics from this chapter. Most of the exercises require implementing new concurrent data structures using atomic variables and the CAS instruction. These data structures can also be solved using the synchronized statement, so it is helpful to contrast the advantages of the two approaches:
- Implement a custom - ExecutionContextclass called- PiggybackContext, which executes- Runnableobjects on the same thread that calls the- executemethod. Ensure that a- Runnableobject executing on the- PiggybackContextcan also call the- executemethod and that exceptions are properly reported.
- Implement a - TreiberStackclass, which implements a concurrent stack abstraction:- class TreiberStack[T] { def push(x: T): Unit = ??? def pop(): T = ??? }- Use an atomic reference variable that points to a linked list of nodes that were previously pushed to the stack. Make sure that your implementation... 
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
        