{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

19 N-Party Mutual Exclusion

19 N-Party Mutual Exclusion - CS-350 Fundamentals of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS-350: Fundamentals of Computing Systems Page 1 of 5 Lecture Notes © Azer Bestavros. All rights reserved. Reproduction or copying (electronic or otherwise) is expressly forbidden except for students enrolled in CS-350. Concurrency and Synchronization: N-Process Mutual Exclusion Recall that we solved the 2-process mutual exclusion problem using Dekker’s and Peterson’s algorithms. We now turn our attention to how we could generalize these algorithms for N processes. Our first impulse may be to try a straightforward extension of the data structures we used for the Dekker/Peterson algorithms. Unfortunately, this does not work. Specifically, we note that the tie-breaking approach (using the variable “ turn ”) does not work readily with N processes. Nevertheless, the general approach we followed in the Dekker/Peterson algorithms is still sound: A process who wishes to enter the critical section still needs to signal its intention to do so. There needs to be a mechanism whereby multiple processes can agree on who is competing for the critical section. In case multiple processes are competing for the resource, they need to resolve this by having a protocol for selecting a “winner.” In the Dekker/Peterson algorithms, the first of the above three phases was satisfied by having intentions flagged; the second was simply a matter of checking the other process’ intention; and the third was simply a matter of breaking the tie in favor of one process or the other based on the value of the variable “ turn. For N processes, we can use the same approach for the first phase. The difficulty is with the second and third phases. Finding out if the other process needed the critical section was a simple check on the other process’ flag, and breaking a tie amongst two processes was delegated to the value of a simple binary variable. For N processes, we could have as few as two and as many as N processes competing for entry. Similarly, we could have as few as two and as many as N locked up in competition for the critical section. This is the challenge. The Bakery Algorithm One approach to guarantee that one process proceeds to the critical section at a time is to issue each process that wishes to enter the critical section a positive number to act as a “ticket.” Processes interested in getting into the critical section could simply compare their tickets and the one with the smallest ticket gets in. Upon exit from the critical section, a process resets the value of its ticket to zero, implying that it is no longer competing for the critical section, thus allowing the holder of the ticket with the (next) smallest positive number, if any, to get in.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}