Consider the analogy of a tunnel with only a single lane. To avoid a deadlock, cars must be prevented from entering the tunnel at both ends simultaneously.

computer science

Description

 

13. Consider the analogy of a tunnel with only a single lane. To avoid a deadlock, cars must be prevented from entering the tunnel at both ends simultaneously. Once a car enters, other cars from the same direction may follow immediately. Ignoring the problem of starvation, write the code using semaphores to solve this problem. (Hint: Consider the readers/writers code given in the previous exercise. The tunnel problem is a variation of the readers/writers problem where multiple readers or multiple writers are allowed to enter the critical region.)


Related Questions in computer science category