Ten threads share an integer array that is initialized by main. Each thread when accessing the shared array has exclusive access. This means that no other thread in the group will be accessing it at that time. Hence, locking is not required. The threads agree to access the threads in sequence where the order of the sequence is determined by main. All the threads are released at the same time and may be executed by the scheduler in any order. However, they may only access the data in the sequence pre-determined by main. In effect this means that each thread must wait for earlier threads in the sequence to complete before accessing the data. There are three kinds of thread: TA adds x to each element in the array; TB decrements each element in the array and TC squares each element in the shared sequence. The number of each kind of thread is determined by main.
A LatchBarrier is a control that forces N threads to rendezvous at a given point. When all threads reach the barrier then they are all released. The threads are automatically released by the barrier when the Nth thread invokes method await on the barrier. This LatchBarrierworks like an automatic Latch and is different from the one provided by Doug Lea discussed in the lecture because it has no countDown method. Using Semaphores write a class that implements such a barrier and test it. How would you write this class using a CountDownLatch?