ASSIGNMENTS for Lab Session 1


  1. 1

    Develop the class ThreadSeqID with the static method get() that returns the ID of the calling thread. IDs are progressive int values, >=0, to be assigned according to the request order.

  2. 2

    Define the interface for a shared counter.

  3. 3

    Develop a program that, making use of a shared counter that is not thread-safe, clearly shows the problems deriving from data races.

  4. 4

    Develop a correct version of the previous program (with a thread-safe shared counter).

  5. 5

    Develop a version of the previous program with an implementation of the (shared) counter based on ThreadLocal.

  6. 6

    Implement a Lock to be used by only two threads, recurring to the Peterson's algorithm. Use such Lock in a program where two threads concurrently make use of a shared data structure, assuring a proper access.