Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 singlelane 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 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 can cause unfairness. Therefore, a maximum of 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 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 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 realtime. For this, create a separate thread that is triggered periodically within a certain time frame to refresh the output continuously.
There is a singlelane 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 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 can cause unfairness. Therefore, a maximum of 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 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 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 realtime. For this, create a separate thread that is triggered periodically within a certain time frame to refresh the output continuously.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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