Question: There is a single - lane road on a river bridge. Naturally, only one direction ( north to south, or south to north ) can

There is a single-lane road on a river bridge. Naturally, only one direction (north to south, or south to north) can pass through the bridge at any given time. If a vehicle comes from the opposite direction, the vehicles get stuck. A maximum of 3 vehicles can be on the bridge at the same time, but all vehicles must be moving in the same direction.
However, if there is heavy two-way traffic, allowing continuous passage in one direction can cause unfairness. Therefore, a maximum of 10 vehicles in a row should be allowed to pass in one direction. An approaching vehicle can pass if the traffic on the bridge is flowing in its direction and fewer than 10 vehicles have passed consecutively. Otherwise, it should wait at the entrance of the bridge. However, if there are no vehicles waiting at the entrance from the opposite direction, more than 10 vehicles can pass consecutively.
Write a software program using the PTHREAD library in C that can manage synchronization, preventing conflicts and congestion, while meeting all these requirements.
Plan each vehicle as a separate thread. Automatically generate vehicles going in random directions within a certain time frame.
The expected output of the assignment is the operation of the program, while also showing the steps of the operation on the screen. You can display the output on the screen in any format you wish.
The numbers represent the vehicle count. The interface should be updated with each created vehicle.
You need to use Semaphores in the application.
Create an output on the terminal as shown below and constantly refresh the output in real-time. For this, create a separate thread that is triggered periodically within a certain time frame to refresh the output continuously.
 There is a single-lane road on a river bridge. Naturally, only

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!