Book Image

Learning Concurrent Programming in Scala

By : Aleksandar Prokopec
5 (1)
Book Image

Learning Concurrent Programming in Scala

5 (1)
By: Aleksandar Prokopec

Overview of this book

Table of Contents (18 chapters)
Learning Concurrent Programming in Scala
About the Author
About the Reviewers


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.

  1. Implement a custom ExecutionContext class called PiggybackContext, which executes Runnable objects on the same thread that calls execute. Ensure that a Runnable object executing on the PiggybackContext can also call execute and that exceptions are properly reported.

  2. Implement a TreiberStack class, 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 is lock-free and not susceptible to the ABA problem.

  3. Implement a ConcurrentSortedList class,...