Question: There is a single - lane road on a river bridge. Naturally, only traffic in the same direction ( from north to south or from

There is a single-lane road on a river bridge. Naturally, only traffic in the same direction (from north to south or from south to north) is allowed on the bridge at any given time. If a vehicle comes from the opposite direction, the vehicles get stuck. At most, 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 would be unfair. Therefore, no more than 10 consecutive vehicles should be allowed to pass in the same direction. A vehicle approaching the bridge can cross if the bridge traffic is flowing in its direction and the number of consecutive vehicles passing is less than 10. Otherwise, it should wait at the bridge entrance. However, if there are no vehicles waiting at the bridge entrance from the opposite direction, more than 10 consecutive vehicles may pass.
Write software using the PTHREAD library in C language that meets all these requirements and prevents conflicts and congestion.
Plan each vehicle as a separate thread. Automatically generate vehicles moving in random directions within a specified time.
The expected output of the assignment is the running program and showing the working steps on the screen. You can display the output in any format you want.
Numbers represent the number of vehicles. The interface should be updated with each created vehicle.
You need to use Semaphore in the application.
Create an output in the terminal as shown below and continuously update the output for real-time updates. For this, create a separate thread and trigger it continuously within a specified time to update the output.
 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!