Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please post working C code and not anything else Your solution to the problem should be written in C and submitted via D2L. An old

image text in transcribed

Please post working C code and not anything else

Your solution to the problem should be written in C and submitted via D2L. An old bridge has only one lane and can only hold at most 3 cars at a time without risking collapse. Write a pthreads program that controls traffic so that at any given time, there are at most 3 cars on the bridge, and all of them are going the same direction. A car calls ArriveBridge when it arrives at the bridge and wants to go in the specified direction (0 or 1); ArriveBridge should not return until the car is allowed to get on the bridge A car calls ExitBridge when it gets off the bridge, potentially allowing other cars to get on. To ensure that cars get to flow in both directions, you are to switch the direction of traffic if cars are waiting from the other direction and 3 cars have crossed. To assist, here are some suggestions .Treat each car as a thread When a car is on the bridge you can put the thread to sleep for a fixed amount of time (same time for all cars) to simulate the time for a car to drive across as each car enters the bridge argument and the main function reads input in the following format to simulate . Your program outputs the direction that traffic is moving on the bridge and the driver . Your program can take the time for a car to cross (in seconds) as a command line scenarios: Direction Arrival im ue Mark 10 For the above input when running your program (indicating 5 seconds for a car to cross) ./a.out 5 Direction: North im Direction: South ue

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

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions