Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with writing C++ code using mutexes OBJECTIVES This rather short assignment should teach you how to use pthreads, pthread mutexes and pthread condition variables

Help with writing C++ code using mutexes

image text in transcribed

image text in transcribed

OBJECTIVES This rather short assignment should teach you how to use pthreads, pthread mutexes and pthread condition variables THE PROBLEM A bridge is load-zoned and can only carry a total wet ght of maxweight tons. Your solution should ensure that the total weight of all vehicles on the bridge will never exceed its maximum load. Each vehicle will be represented by a separate thread and all inter-thread synchronization must be implemented through pthread mutexes and pthread condition variables. You cannot use senna Vehicles whose total loaded we exceeds the oad of the bridge should be rejected and a descriptive message containing the serial number of the vehicle printed out. YOUR PROGRAM Your program should consist of l. A main program, 2. An enter Bridge (weight) method to be performed by each arriving vehicle 3. A leave Bridge(weight) method to be performed by each vehicle leaving the bridge, and 4. One child thread per vehicle. The maxweight constant should be read from the mmand line as in /a.out 10 All other parameters will be re ad from the standard input. Each input line will describe one vehicle arriving at the bridge and will contain four parameters An alphanumeric string without spaces representing the car license plate, 2. A positive integer representing the number of seconds elapsed since the arrival ofthe previous vehicle (it wi be equal to zero for the first vehicle arriving to the bridge) 3. A positive integer representing the total loaded weight of the vehicle rounded up to an integer number of tons, 4. A positive integer representing the number of seconds the vehicle will take to cross the bridge. A possible set ofinput could be: HIOFCR. 1 10 STOL3N 3 10 20 SHKSPR. 1 30 2DIE4 BYOFCR. 1 15 Your main program should read the input lineper line, wait for the appropriate amount of time and fork a differen child process for each incoming vehicle. It should print out a descriptive message including the vehicle license number and the current bridge load every time a vehicle: l. Arrives at the bridge, 2. Starts crossing the bridge, and 3. Leaves the bridge The current bridge load when a vehicle starts cros the bridge includes the wei right of that vehicle but the current bridge load after a vehicle leaves the bridge does not. HINTS Create your mutexes and your condition variables in your main program before you fork any child thread. This document was updated last on Thursday, April 06, 2017 PTHREADS I. Dont forget the pthread include: #include

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

Students also viewed these Databases questions

Question

=+5 Evaluate whether the CCT program was effective.

Answered: 1 week ago

Question

=+Identify the type of global assignment for which CCT is needed.

Answered: 1 week ago