Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NOTE: ITS A PROGRAMMING SOLVING QUESTION SO HAVE TO DO IT BY C LANGUAGE. MAKE SURE UPLOAD THE PROGRAM OUTPUT AS WELL. 3. An old

NOTE: ITS A PROGRAMMING SOLVING QUESTION SO HAVE TO DO IT BY C LANGUAGE. MAKE SURE UPLOAD THE PROGRAM OUTPUT AS WELL.

image text in transcribed

image text in transcribed

3. 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. Don't worry about starving cars trying to go in one direction; just make sure cars are always on the bridge when they can be. To assist your programming 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 * Your program outputs the direction that traffic is moving on the bridge and the driver as each car enters the bridge

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

Students also viewed these Databases questions