Concurrent Programming - Course Work 1

1a P, Q and R are indivisible actions, for the concurrent program: (P || Q || R), executed on a single physical processor list all the legal execution orderings.

b If P is x = 3; Q is y = 5; and R is z = x + y; list all the possible values of z which can be computed by the program of part a, given that x and y are initially zero.

c Modify the program from part a such that the maximum value for z is always computed. Your solution should still retain some concurrent execution.

2 A barrier is an object used to synchronize multiple threads. Each of n threads wait at the barrier until all n threads are at the barrier, then all n processes proceed. Give the code for the following class which implements barrier synchronization.

class Barrier {
     Barrier(int n) {} // n threads
     public synchronized void waitAll() {}
}

For fun

Write a Java applet which demonstrates the operation of the Barrier class. Mail demo code/ URL to me at jnm@doc.ic.ac.uk.. I will include the best demonstration in the course Web pages.