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, 22.06.2019 03:00
Check my work the microprocessor is a(n) circuit, which is designed to process data based on a set of instructions. most desktop and laptop devices contain a microprocessor based on the standard. most tablets and smartphones contain processors based on technology. a microprocessor's circuitry is designed to perform a limited number of tasks contained in its set. during processing, an instruction is loaded into the processor's unit. data is loaded into registers in the processor's where arithmetic and logic operations are performed. microprocessor performance can be measured by its speed. other factors affecting overall processing performance include word size, cache size, and instruction set complexity. most digital devices contain only one microprocessor chip, but today's multi- processors contain circuitry that supports parallel processing. computers contain various kinds of memory. random memory is a special holding area for data, program instructions, and the system. it stores data on a temporary basis until the processor makes a data request. ram is different from disk storage because it is , which means that it can hold data only when the computer power is turned on. computers also contain read- memory, which is a type of non-volatile memory that provides a set of "hard-wired" instructions, called the loader, that a computer uses to boot up.
Answers: 3
question
Computers and Technology, 22.06.2019 16:30
Which of the following statements best describes it careers?
Answers: 2
question
Computers and Technology, 22.06.2019 21:00
Write a method so that the main() code below can be replaced by the simpler code that calls method original main(): public class calcmiles { public static void main(string [] args) { double milesperhour; double minutestraveled; double hourstraveled; double milestraveled; milesprhour = scnr.nextdouble(); minutestraveled = scnr.nextdouble(); hourstraveled = minutestraveled / 60.0; milestraveled = hourstraveled * milesperhour; system.out.println("miles: " + milestraveled); } }
Answers: 2
question
Computers and Technology, 23.06.2019 18:00
Apunishment or the threat of punishment used to enforce conformity. select the best answer from the choices provided t f
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
question
Mathematics, 18.03.2021 18:50
question
Social Studies, 18.03.2021 18:50
question
Mathematics, 18.03.2021 18:50
question
English, 18.03.2021 18:50
question
Social Studies, 18.03.2021 18:50
Questions on the website: 13722363