Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Peterson's algorithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== {{anchor|Filter algorithm}}Filter algorithm: Peterson's algorithm for more than two processes === [[File:Snapshot of filter algorithm (Peterson's algorithm for more than 2 processes) in progress.png|thumb|Snapshot of filter algorithm with 10 processes in progress. Last to enter are shown bold and underlined. (NB: Depending on scheduling, the last to enter may not be "correct".) At any time, updates to the table could be: the insertion of a new process at level 0, a change to the last to enter at a given level, or a process moving up one level (if it is not the last to enter OR there are no other processes at its own level or higher).]] The filter algorithm generalizes Peterson's algorithm to {{math|''N'' > 2}} processes.<ref name="art">{{cite book |title=The Art of Multiprocessor Programming |first1=Maurice |last1=Herlihy |authorlink1=Maurice Herlihy |first2=Nir |last2=Shavit |authorlink2=Nir Shavit |publisher=Elsevier |year=2012 |pages=28β31 |isbn=9780123977953}}</ref> Instead of a boolean flag, it requires an integer variable per process, stored in a single-writer/multiple-reader (SWMR) atomic [[Register machine|register]], and {{math|''N'' β 1}} additional variables in similar registers. The registers can be represented in [[pseudocode]] as [[Array data type|array]]s: level : array of N integers last_to_enter : array of N β 1 integers The {{mono|level}} variables take on values up to {{math|''N'' β 1}}, each representing a distinct "waiting room" before the critical section.{{r|art}} Processes advance from one room to the next, finishing in room {{math|''N'' β 1}}, which is the critical section. Specifically, to acquire a lock, process {{mvar|i}} executes{{r|raynal}}{{rp|22}} i β ProcessNo '''for''' β '''from''' 0 '''to''' N β 1 '''exclusive''' level[i] β β last_to_enter[β] β i '''while''' last_to_enter[β] = i '''and''' there exists k β i, such that level[k] β₯ β '''wait''' To release the lock upon exiting the critical section, process {{mvar|i}} sets {{mono|level[i]}} to β1. That this algorithm achieves mutual exclusion can be proven as follows. Process {{mvar|i}} exits the inner loop when there is either no process with a higher level than {{mono|level[i]}}, so the next waiting room is free; or, when {{mono|i β last_to_enter[β]}}, so another process joined its waiting room. At level zero, then, even if all {{mvar|N}} processes were to enter waiting room zero at the same time, no more than {{math|''N'' β 1}} will proceed to the next room, the final one finding itself the last to enter the room. Similarly, at the next level, {{math|''N'' β 2}} will proceed, [[Mathematical induction|etc.]], until at the final level, only one process is allowed to leave the waiting room and enter the critical section, giving mutual exclusion.{{r|raynal}}{{rp|22β24}} Unlike the two-process Peterson algorithm, the filter algorithm does not guarantee bounded waiting.{{r|raynal}}{{rp|25β26}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)