Answered step by step
Verified Expert Solution
Link Copied!

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 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.
image text in transcribed

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

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions