Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Dekker's algorithm
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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!
== Overview == If two processes attempt to enter a [[critical section]] at the same time, the algorithm will allow only one process in, based on whose {{mono|turn}} it is. If one process is already in the critical section, the other process will [[busy wait]] for the first process to exit. This is done by the use of two flags, {{mono|wants_to_enter[0]}} and {{mono|wants_to_enter[1]}}, which indicate an intention to enter the critical section on the part of processes 0 and 1, respectively, and a variable {{mono|turn}} that indicates who has priority between the two processes. [[File:Dekker's Algorithm.svg|thumb|Dekker's algorithm]] Dekker's algorithm can be expressed in [[pseudocode]], as follows.<ref>{{cite journal |title=Some Myths About Famous Mutual Exclusion Algorithms |first=K. |last=Alagarsamy |journal=ACM SIGACT News |pages=94β103 |year=2003 |volume=34 |issue=3|doi=10.1145/945526.945527 |s2cid=7545330 }}</ref> {| style="margin:1em auto; width:75%" | colspan="2" align="left"| <syntaxhighlight lang="text"> variables wants_to_enter : array of 2 booleans turn : integer wants_to_enter[0] β false wants_to_enter[1] β false turn β 0 // or 1 </syntaxhighlight> |- | align="left" | <syntaxhighlight lang="text"> p0: wants_to_enter[0] β true while wants_to_enter[1] { if turn β 0 { wants_to_enter[0] β false while turn β 0 { // busy wait } wants_to_enter[0] β true } } // critical section ... turn β 1 wants_to_enter[0] β false // remainder section </syntaxhighlight> |align="left" | <syntaxhighlight lang="text"> p1: wants_to_enter[1] β true while wants_to_enter[0] { if turn β 1 { wants_to_enter[1] β false while turn β 1 { // busy wait } wants_to_enter[1] β true } } // critical section ... turn β 0 wants_to_enter[1] β false // remainder section </syntaxhighlight> |} Processes indicate an intention to enter the critical section which is tested by the outer while loop. If the other process has not flagged intent, the critical section can be entered safely irrespective of the current turn. Mutual exclusion will still be guaranteed as neither process can become critical before setting their flag (implying at least one process will enter the while loop). This also guarantees progress as waiting will not occur on a process which has withdrawn intent to become critical. Alternatively, if the other process's variable was set, the while loop is entered and the turn variable will establish who is permitted to become critical. Processes without priority will withdraw their intention to enter the critical section until they are given priority again (the inner while loop). Processes with priority will break from the while loop and enter their critical section. Dekker's algorithm guarantees [[mutual exclusion]], freedom from [[deadlock (computer science)|deadlock]], and freedom from [[Resource starvation|starvation]]. Let us see why the last property holds. Suppose p0 is stuck inside the {{mono|while wants_to_enter[1]}} loop forever. There is freedom from deadlock, so eventually p1 will proceed to its critical section and set {{mono|1=turn = 0}} (and the value of turn will remain unchanged as long as p0 doesn't progress). Eventually p0 will break out of the inner {{mono|while turn β 0}} loop (if it was ever stuck on it). After that it will set {{mono|wants_to_enter[0]}} to true and settle down to waiting for {{mono|wants_to_enter[1]}} to become false (since {{mono|1=turn = 0}}, it will never do the actions in the while loop). The next time p1 tries to enter its critical section, it will be forced to execute the actions in its {{mono|while wants_to_enter[0]}} loop. In particular, it will eventually set {{mono|wants_to_enter[1]}} to false and get stuck in the {{mono|while turn β 1}} loop (since turn remains 0). The next time control passes to p0, it will exit the {{mono|while wants_to_enter[1]}} loop and enter its critical section. If the algorithm were modified by performing the actions in the {{mono|while wants_to_enter[1]}} loop without checking if {{mono|1=turn = 0}}, then there is a possibility of starvation. Thus all the steps in the algorithm are necessary.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Dekker's algorithm
(section)
Add topic