Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assume that we have a wooden bridge for persons to cross between two mountains. The bridge can hold a max number of persons. Up to
Assume that we have a wooden bridge for persons to cross between two mountains. The bridge can hold a max number of persons. Up to persons can be hanging on the bridge at any one time. The bridge serve crossing from two directions east to west westward and west to east eastward Use semaphore to solve the problem of synchronizing passengers crossing the bridge.
Each person operates in a separate thread, and functions as follow:
void personint id Destination dest
Wait Until Safe To Cross the destination your code to synchronize
CrossBridgeid dest; CS
Done With Crossing the destination; your code after cross is done
a For this part, you solution should ensure that:
a i At most persons simultaneously execute CrossBridge
b All persons executing in CrossBridge are heading in the same direction.
c Avoid starvation
d The first person in the same direction acquire the bridge, last one release the bridge
b For this part assume that persons can go in the two directions at the same time, your solution must ensure the following:
i At most eastwardmoving persons simultaneously execute CrossBridge
ii At most westwardmoving persons simultaneously execute CrossBridge
iii At most K persons simultaneously execute CrossBridge
iv you solution should maximize the throughput under above conditions.
For the two parts solutions
In your submission, make the following clear:
shared semaphores; declarations and value assignment, add comment to explain for what each semaphore is used for in the code of the Person, add comment to explain the code especially the use of wait and signal functions
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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