The Roomsclass manages a collection of rooms, indexed from 0 tom−1(m is an argument to the constructor). Threads can enter or exit any room in that range. Each room can hold an arbitrary number of...


The Roomsclass manages a collection of rooms, indexed from 0 tom−1(m is an argument to the constructor). Threads can enter or exit any room in that range. Each room can hold an arbitrary number of threads simultaneously, but only one room can be occupied at a time. For example, if there are two rooms, indexed 0 and 1, then any number of threads might enter room 0, but no thread can enter room 1 while room 0 is occupied. Fig.8.13 shows an outline of the Rooms class. Each room can be assigned an exit handler: Calling set Exit Handler(i, h)sets the exit handler for room It o handler h. The exit handler is called by the last thread to leave a room, but before any threads subsequently enter any room. This method is called once per room and while it is running, no threads are in any rooms. Implement the Rooms class. Make sure that:


• If some thread is in room i, then no thread is in room j=i.


• The last thread to leave a room calls the room’s exit handler, and no threads are in any room while that handler is running.


• Your implementation is fair: Any thread that tries to enter a room eventually succeeds. (You may assume that every thread that enters a room eventually leaves.)




Dec 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here