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
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Exercises


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.

  1. Implement a parallel method, which takes two computation blocks a and 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)
  2. Implement a periodically method, which takes a time interval duration specified in milliseconds, and a computation block b. The method starts a thread that executes the computation block b every duration milliseconds. It should...