Question: Now consider another correct solution to the preceding problem: a. Explain how this program works and why it is correct. b. Does this solution differ

Now consider another correct solution to the preceding problem:

1 semaphore mutex 1, block 0; 2 int active 0, waiting -

a. Explain how this program works and why it is correct.
b. Does this solution differ from the preceding one in terms of the number of processes that can be unblocked at a time? Explain.
c. This program is an example of a general design pattern that is a uniform way to implement solutions to many concurrency problems using semaphores. It has been referred to as the Pass The Baton pattern. Describe the pattern.

1 semaphore mutex 1, block 0; 2 int active 0, waiting - 0; boolean must_wait false; 3 4 5 6 semWait (mutex); if (must wait) { ++waiting; semSignal (mutex); semwait (block); --waiting; 7 8 9 10 11 }) 12 ++active; 13 must wait - active -- 3; 14 if (waiting > 0 && !must_wait) semSignal (block) ;; 15 16 17 else semSignal (mutex); 18 19 /* critical section */ 20 21 semWait (mutex); 22-active; if (active - 0) 23 24 must wait false; 25 if (waiting - 0 && !must_wait) 26 semSignal (block) ;; 27 28 else semSignal (mutex); /* share variables: semaphores, */ /* counters, and / /* state information */ /* Enter the mutual exclusion */ /* If there are (or were) 3, then */ /* Wait for all current users to depart */ /* We've got the mutual exclusion; update count */ /* we must wait, but we must leave */ /* the mutual exclusion first */ /* Update active count, and remember */ /* if the count reached 3 */ /* If there are others waiting */ /* and we don't yet have 3 active, */ /* unblock a waiting process */ open the mutual exclusion */ /* otherwise /* Enter mutual exclusion */ /* and update the active count */ /* If last one to leave? */ /* set up to let new processes enter */ /* If there are others waiting / /* and we don't have 3 active, */ /* unblock a waiting process */ open the mutual exclusion */ /* otherwise

Step by Step Solution

3.38 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ANSWER a This program works by first acquiring the mutex semaphore If the mustwait flag is set then ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating Systems Internals And Design Principles Questions!