Question 1

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.

Question 2

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?

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.