Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Narrow Bridge Synchronization There is a single - lane road on a bridge over a river. Naturally, at any given moment, only one direction of
Narrow Bridge Synchronization
There is a singlelane road on a bridge over a river. Naturally, at any given moment, only one direction of traffic either north to south, or south to north is allowed on the bridge. If a vehicle comes from the opposite direction, vehicles get stuck. At any given time, there can be a maximum of vehicles on the bridge, but all vehicles must be moving in the same direction.
However, if there is congestion in both directions of traffic, constantly allowing passage in one direction leads to unfairness. Therefore, only up to vehicles in a row should be allowed to cross in one direction. A vehicle approaching the bridge can pass if the traffic on the bridge is flowing in the same direction it intends to go and if there are fewer than consecutive vehicles. Otherwise, it must wait at the beginning of the bridge. However, if there are no vehicles waiting at the beginning of the bridge from the opposite direction, more than vehicles in a row can pass.
Code a software that can manage synchronization satisfying all these requirements and prevent conflicts and congestion using the PTHREAD library in C
Plan each vehicle as a separate thread. Generate vehicles automatically in random directions within a specified time.
The expected output of the assignment is the program running as well as displaying the working steps on the screen. You can display the output in any format you want. The expected quality of the output is as follows.
You need to use Semaphore in the application.
Generate output in the terminal as shown below and constantly refresh the output for realtime updating. Create a separate thread to continuously trigger the output refresh within a specified time interval.
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