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
ExecutionContext
class calledPiggybackContext
, which executesRunnable
objects on the same thread that calls theexecute
method. Ensure that aRunnable
object executing on thePiggybackContext
can also call theexecute
method and that exceptions are properly reported. - Implement a
TreiberStack
class, which implements a concurrent stack abstraction:class TreiberStack[T] { def push(x: T): Unit ...
Get Learning Concurrent Programming in Scala - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.