Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please post working C code and not anything else Your solution to the problem should be written in C and submitted via D2L. An old
Please post working C code and not anything else
Your solution to the problem should be written in C and submitted via D2L. An old bridge has only one lane and can only hold at most 3 cars at a time without risking collapse. Write a pthreads program that controls traffic so that at any given time, there are at most 3 cars on the bridge, and all of them are going the same direction. A car calls ArriveBridge when it arrives at the bridge and wants to go in the specified direction (0 or 1); ArriveBridge should not return until the car is allowed to get on the bridge A car calls ExitBridge when it gets off the bridge, potentially allowing other cars to get on. To ensure that cars get to flow in both directions, you are to switch the direction of traffic if cars are waiting from the other direction and 3 cars have crossed. To assist, here are some suggestions .Treat each car as a thread When a car is on the bridge you can put the thread to sleep for a fixed amount of time (same time for all cars) to simulate the time for a car to drive across as each car enters the bridge argument and the main function reads input in the following format to simulate . Your program outputs the direction that traffic is moving on the bridge and the driver . Your program can take the time for a car to cross (in seconds) as a command line scenarios: Direction Arrival im ue Mark 10 For the above input when running your program (indicating 5 seconds for a car to cross) ./a.out 5 Direction: North im Direction: South ueStep 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