Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Rooms class manages a collection of rooms , indexed from 0 to m 1 ( m is an argument to the constructor). Threads

The Rooms class manages a collection of rooms, indexed from 0 to m − 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 setExitHandler(i, h) sets the exit handler for room i to handler h. The exit handler is called by the last thread to

FIGURE 8.13

The Rooms class.

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.)
 

public class Rooms ( public interface Handler { void onEmpty(); public Rooms (1nt m) ... }; public votd enter(1nt i) { ... }; public boolean exit () (... ); public void setExitHandler (1nt i, Rooms.Handler h) ... };

Step by Step Solution

3.40 Rating (150 Votes )

There are 3 Steps involved in it

Step: 1

Problem arise if a push runs concurrently with a pop Suppose p... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming the World Wide Web

Authors: Robert W. Sebesta

8th edition

133775984, 9780133776096 , 978-0133775983

More Books

Students also viewed these Accounting questions

Question

What are the two categories of Flash components?

Answered: 1 week ago

Question

What do the methods setMaxAge, setValue, and getComment do?

Answered: 1 week ago

Question

What is the task of a DNS name server?

Answered: 1 week ago

Question

5.7 Describe the role of cultural code frame switching.

Answered: 1 week ago

Question

2. What are the three different ethics described by Jensen?

Answered: 1 week ago