Question: 1 . ( 2 5 points ) Exercise 6 . 2 0 ( fixing HardwareData ) The HardwareData class in this programLinks to an external

1.(25 points) Exercise 6.20(fixing HardwareData)
The HardwareData class in this programLinks to an external site. abstracts the idea of the get-and-set and swap instructions. However, this class is not considered thread safe, because multiple threads may concurrently access its methods and thread safety required that each method be performed atomically. Rewrite the class HardwareData methods using Java synchronization so that they are thread safe.
2.Exercise 6.22(interface Channel)
Implement the Channel interface (see page 127 in the book's Edition 8 and/or Sample Projects in Module 2) so that the send() and receive() methods of the Message Queue are blocking. That is, a thread invoking send() will block if the channel is full. If the channel is empty, a thread invoking receive() method will similarly block. To do this will require storing the messages in a fixed-length array. Ensure that your implementation is thread safe (using Java synchronization) and that the messages are stored in the FIFO order.
3. Exercise 6.24(The Sleeping Barber Problem)
A barber shop consists of a waiting room with 10 chairs and a barber room with one barber chair. If there are no customers to be served, the barber goes to sleep. If a customer enters the barbershop and all chairs are occupied, then the customer leaves the shop. If the barber is busy but chairs are available, then the customer sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber, Write a program to coordinate the barber and the customers using Java synchronization.
4. Exercise 7.15(the single-lane bridge problem)
A single-lane bridge connects two villages of North Tunbridge and South Tunbridge. Farmers in the two villages use this bridge to deliver their produce to the neighboring town. The bridge can become deadlocked if both a northbound and a southbound farmer get on the bridge at the same time (assume that farmers are stubborn and are unable to back up). Use Java synchronization to design an algorithm that prevents deadlock. Initially, do not be concerned about starvation (the situation in which northbound farmers prevent southbound farmers from using the bridge, or vice versa).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!