Two mountain resorts are connected by a road that becomes single lane inside a tunnel that...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Two mountain resorts are connected by a road that becomes single lane inside a tunnel that goes through the mountain. One resort is at the left end of the tunnel and the other at the right end of the tunnel. Cars moving from left to right are called "Right-bound" cars and are indicated with odd numbers starting from 1 (1, 3, 5, ...). "Left-bound" cars move from right to left and are indicated with even numbers starting from 0 (0, 2, 4, ..). The tunnel can become deadlocked if a left-bound and a right-bound car enter into the tunnel at the same time. Task: Write a program that synchronizes movement of cars through the tunnel in such a way that prevents the deadlock. You may use any synchronization technique. For example, semaphores would be a good choice. You can assume that there will be steady stream of cars from each side, however, there can be more than one car from one side before we see a car from the opposite side. The tunnel may allow more than one car passing through it, but only in one direction. Cars do not need to have same speed (the time they spend to pass the tunnel). Once a particular car enters and leaves the tunnel, it does not come back again to enter the tunnel. User is not expected to supply any input. The user will simply compile and run your program. A segment from a sample output could be like the following: Right-bound Car I wants to enter the tunnel. Right-bound Car I is in the tunnel. Right-bound Car I is exiting the tunnel. Left-bound Car 4 wants to enter the tunnel. Left-bound Car 4 is in the tunnel. Left-bound Car 4 is exiting the tunnel. Right-bound Car 5 wants to enter the tunnel. Right-bound Car 5 is in the tunnel. Left-bound Car 8 wants to enter the tunnel. // note: Car 8 cannot enter as Car 5 is already in tunnel Right-bound Car 5 is exiting the tunnel. Left-bound Car 8 is in the tunnel. // note: now car 8 can go as car 5 has left the tunnel Right-bound Car 7 wants to enter the tunnel. // note: Car 7 cannot enter as Car 8 is already in tunnel Left-bound Car 10 wants to enter the tunnel. // note: the tunnel may have allowed 10 to enter Left-bound Car 8 is exiting the tunnel. Left-bound Car 10 is in the tunnel. // note: this could have been before the previous statement Left-bound Car 12 wants to enter the tunnel. *** [Hint: you may create two threads for controlling left-bound and right-bound cars. You may also use Thread.sleep() with different sleep times for left-bound and right-bound cars when they enter tunnel. This would allow simulating different time taken to pass the tunnel. You may also use synchronized controller Two mountain resorts are connected by a road that becomes single lane inside a tunnel that goes through the mountain. One resort is at the left end of the tunnel and the other at the right end of the tunnel. Cars moving from left to right are called "Right-bound" cars and are indicated with odd numbers starting from 1 (1, 3, 5, ...). "Left-bound" cars move from right to left and are indicated with even numbers starting from 0 (0, 2, 4, ..). The tunnel can become deadlocked if a left-bound and a right-bound car enter into the tunnel at the same time. Task: Write a program that synchronizes movement of cars through the tunnel in such a way that prevents the deadlock. You may use any synchronization technique. For example, semaphores would be a good choice. You can assume that there will be steady stream of cars from each side, however, there can be more than one car from one side before we see a car from the opposite side. The tunnel may allow more than one car passing through it, but only in one direction. Cars do not need to have same speed (the time they spend to pass the tunnel). Once a particular car enters and leaves the tunnel, it does not come back again to enter the tunnel. User is not expected to supply any input. The user will simply compile and run your program. A segment from a sample output could be like the following: Right-bound Car I wants to enter the tunnel. Right-bound Car I is in the tunnel. Right-bound Car I is exiting the tunnel. Left-bound Car 4 wants to enter the tunnel. Left-bound Car 4 is in the tunnel. Left-bound Car 4 is exiting the tunnel. Right-bound Car 5 wants to enter the tunnel. Right-bound Car 5 is in the tunnel. Left-bound Car 8 wants to enter the tunnel. // note: Car 8 cannot enter as Car 5 is already in tunnel Right-bound Car 5 is exiting the tunnel. Left-bound Car 8 is in the tunnel. // note: now car 8 can go as car 5 has left the tunnel Right-bound Car 7 wants to enter the tunnel. // note: Car 7 cannot enter as Car 8 is already in tunnel Left-bound Car 10 wants to enter the tunnel. // note: the tunnel may have allowed 10 to enter Left-bound Car 8 is exiting the tunnel. Left-bound Car 10 is in the tunnel. // note: this could have been before the previous statement Left-bound Car 12 wants to enter the tunnel. *** [Hint: you may create two threads for controlling left-bound and right-bound cars. You may also use Thread.sleep() with different sleep times for left-bound and right-bound cars when they enter tunnel. This would allow simulating different time taken to pass the tunnel. You may also use synchronized controller
Expert Answer:
Answer rating: 100% (QA)
To implement a program that synchronizes the movement of cars through the tunnel to prevent deadlock... View the full answer
Related Book For
Project Management The Managerial Process
ISBN: 9781260570434
8th Edition
Authors: Eric W Larson, Clifford F. Gray
Posted Date:
Students also viewed these programming questions
-
5 Combinatorial Logic Circuits Three people A,B, and C decide to vote yes (1) or no (0) on Poolla for President. Your job is to build a circuit that calculates the majority vote. The output of the...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Consider the following system differential equation: d+y(t) dy(t) dt3 dt4 +5 7 dy(t) dt +36 dy(t) dt - 100y(t) b) Find the transfer function for the system, G(s) = = du(t) dt + 5u(t) a) Find the...
-
The CCl4 molecule belongs to the point group Td. List the symmetry elements of the group and locate them in the molecule.
-
The April transactions of Wiset Company are described in Problem 7-2A. In Problem 7-2 Wiset Company completes these transactions during April of the current year (the terms of all its credit sales...
-
How can HRIS T&D applications help firms foster organizational learning?
-
Dr. Ivan I. Incisor and his wife Irene are married and file a joint return for 2013. Ivan's Social Security number is 477-34-4321 and he is 48 years old. Irene I. Incisor's Social Security number is...
-
1. Graph the functions: a. y = 2x (= b. y =
-
The irreversible first-order (wrt partial pressure of A) gas-phase reaction A B is carried out isothermally in a "fluidized" catalytic CSTR containing 50 kg of catalyst. Currently, 50% conversion is...
-
2. A container weighs 640 lb. The container will be used to drop supplies into a remote area. Assume the initial velocity of the container is zero as it is dropped from a plane. The container is...
-
a function's return data type must be the same as the function's parameters?
-
(i) A 0.54 kg stone is launched vertically from the surface of Earth with an initial speed of 20.0 m/s. Ignoring air resistance, calculate: (a) the maximum height reached by the stone and (b) its...
-
Star A is 4 . 7 9 light years away from earth. How long, in years, does it take for light from Star A to get to Earth?
-
The wavelength of the laser is 5 3 0 nm . How many intensity maxima can be seen on the shaders placed behind the grating, when the grating has 3 4 0 slits per millimeter.
-
What is a directory service (such as Microsoft Active Directory, Novell, e-Directory, etc.)? Under what circumstances would you recommend its implementation for a client? Why do you think an...
-
The effect of channeling increases the enzyme reaction rate by preventing intermediates from defusing to the active site (true or false)?
-
Refer to Exercise 8.S.I. Construct a scatterplot of the data. Does the appearance of the scatterplot indicate that the pairing was effective? Explain. Exercise 8.S.I. A volunteer working at an animal...
-
Exercise Figure 5.1 is a project WBS with cost apportioned by percentages. If the total project cost is estimated to be $800,000, what are the estimated costs for the following deliverables? a ....
-
1 . What are the disadvantages of concurrent engineering (fast tracking)? 2 . What kinds of projects should avoid using concurrent engineering?
-
On June 23, 2018, in Thailand, a group of 12 boys aged between 11 and 17 from the local football team, named the Wild Boars, and their 23-year-old assistant coach entered the Tham Luang cave. Tham...
-
Define and distinguish between an open and a closed adoption.
-
Define and distinguish between an independent and an agency adoption.
-
Define and give an example of an equitable adoption.
Study smarter with the SolutionInn App