In the following set of exercises, you are required to implement higher-level concurrency abstractions in terms of basic JVM concurrency primitives. Some of these exercises introduce concurrent counterparts of sequential programming abstractions, and, in doing so, highlight important differences between sequential and concurrent programming. The exercises are not ordered in any particular order, but some of them rely on specific content from earlier exercises or this chapter.
parallelmethod, which takes two computation blocks
b, and starts each of them in a new thread. The method must return a tuple with the result values of both the computations. It should have the following signature:
def parallel[A, B](a: =>A, b: =>B): (A, B)
periodicallymethod, which takes a time interval
durationspecified in milliseconds, and a computation block
b. The method starts a thread that executes the computation block
durationmilliseconds. It should...