Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 singlelane 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, 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 twoway traffic, allowing continuous passage in one direction would be unfair. Therefore, no more than 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 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 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 realtime updates. For this, create a separate thread and trigger it continuously within a specified time to update the output.
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