subject

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 leftbound and a right-bound car enter into the tunnel at the same time. task: write a program that prevents the deadlock. you may use any synchronization technique. for example, semaphores would be good choice. you may ignore starvation, that is, the situation in which left-bound cars prevent rightbound cars to enter into the tunnel, or vice versa. 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. 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 1 wants to enter the tunnel. right-bound car 1 is in the tunnel. right-bound car 1 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 tunnelcaution: two cars from opposite sides cannot be in the tunnel at the same time. so if “right-bound car x in the tunnel” appears in the output with ‘x’ being odd, there must be a “right-bound car x exiting the tunnel” in the output before a “left-bound car y in the tunnel” appears in the output with ‘y’ being even. another caution: if ‘car m’ and ‘car n’ are waiting to enter tunnel from same direction, the car which is first will enter the tunnel first. also, once a particular car enters and then leaves the tunnel, it does not come back again 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 method and use wait() and notify()/notifyall() appropriately. ]

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 19:10
Select the correct answer. emma, the quality control manager in a software development company, asks the testing team to check whether the user interface is friendly. to which type of testing is emma referring? a. usability testing b. data comparison c. validation testing d. stress testing e. destruction testing
Answers: 1
question
Computers and Technology, 22.06.2019 21:30
How do you take a green screen out of the video while editing?
Answers: 2
question
Computers and Technology, 23.06.2019 07:30
Which option allows you to view slides on the full computer screen?
Answers: 1
question
Computers and Technology, 23.06.2019 17:30
What are the most commonly found items in the trash according to the municipal solid waste report?
Answers: 1
You know the right answer?
Two mountain resorts are connected by a road that becomes single lane inside a tunnel that goes thro...
Questions