Answered step by step
Verified Expert Solution
Link Copied!

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 single-lane 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 3 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 10 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 10 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 10 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 real-time 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

a sin(2x) x Let f(x)=2x+1 In(be)

Answered: 1 week ago