Answered step by step
Verified Expert Solution
Link Copied!

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 'K' 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 person(int id, Destination dest){
Wait Until Safe To Cross the destination// your code to synchronize
CrossBridge(id, 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 10 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 M eastward-moving persons simultaneously execute CrossBridge()
ii) At most N westward-moving 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
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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions