Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need some help with this assignment using threads and semaphores. of input each time the traffic direction changes and one line of output each time
Need some help with this assignment using threads and semaphores.
of input each time the traffic direction changes and one line of output each time a car (a) arrives at the tunnel, (b) enters the tunnel and (c) leaves the tunnel. This line OBJECTIVE This project will familiarize you with the use of pthreads, pthread mutexes and pthread condition variables of output should identify each car by (a) its sequence number in the input file, starting with 1, and (b) whether the car is Whittier-bound or Bear Valley-bound THE PROBLEM The city of Whittier, AK is linked to the outside world by a one-lane tunnel. It is 2.3 mile long, making it the second longest tunnel in the US and links Whittier with Bear Valley. The tunnel is operated according to a time division scheme giving to each direction 15 minutes of crossing time followed by 15 minutes of transition time during which no car can enter the tunne You are to simulate the operation of the tunnel using semaphores and a shared memory segment Your program should consist of 1. A main thread that will fork a tunnel process and The tunnel is now open to Whittier-bound traffic. Car #1 going to Whittier arrives at the tunnel . Car #1 going to Whittier enters the tunnel Car #1 going to Whittier exits the tunnel. Car #2 going to Bear Valley arrives at the tunnel. Car # 3 going to Whittier arrives at the tunnel. Car # 3 going to Whittier enters the tunnel. The tunnel is now closed to ALL traffic. Car # 3 going to Whittier exits the tunnel The tunnel is now open to Bear Valley-bound traffic Car # 2 going to Bear Valley enters the tunnel . Car # 2 going to Bear Valley exits the tunnel 1 car(s) going to Bear Valley arrived at the tunnel 2 car(s) going to Whittier arrived at the tunnel the car processes according to the input At the end of the simulation, your program should also print a summary with specifications 1. The total number ofWhittier-bound cars that 2. A tunnel thread that will start by allowing traffic arrived at the tunnel; arrived at the tunnel the tunnel was full going to Whittier for five seconds, then disallow access to the tunnel for five seconds, then 2. The total number of Bear Valley-bound cars that allow traffic from Whittier for five seconds, before disallowing again the traffic for five seconds and 3. The total number of cars that had to wait because repeating the cycle 3. One car thread per car wanting to cross the tunnel This summary could look like either from Whittier or from Bear Valley The input to your program consists of the maximum number of cars in the tunnel, the tunnel travel time and an ordered list of arriving cars as in: 10 //up to ten cars in the tunnel 1 WB 1 / car bound for Whittier arrives at t 1s // will take 1s to cross 2 BB 2 // car bound for Bear Valley arrives 2s after // will take 2s to cross 1 WB 1 // car bound for Whittier arrives 1s after // will take 1s to cross 2 car(s) going to Whittier arrived at the tunnel 1 car(s) going to Bear Valley arrived at the tunnel 0 car(s) had to wait because the tunnel was full PTHREADS Don't forget the pthread include #include All variables that will be shared by all threads must 1.Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started