Skip to content

Dekker's algorithm is the first known correct solution to the mutual exclusion problem in concurrent programming.

License

Notifications You must be signed in to change notification settings

javaf/dekker-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dekker's algorithm is the first known correct solution to the mutual exclusion problem in concurrent programming. The solution is attributed to Dutch mathematician Th. J. Dekker by Edsger W. Dijkstra. It allows two threads to share a single-use resource without conflict, using only shared memory for communication.

Java already provides a ReentrantLock. This is for educational purposes only.

Course: Concurrent Data Structures, Monsoon 2020
Taught by: Prof. Govindarajulu Regeti

process(i):
1. I want to enter CS.
2. If you want CS too  ...
3a. If its my turn, retry 2.
4a. If its your turn, i dont want to enter.
4b. I wait for you turn to complete.
4c. I now want to enter, retry 2.
5. I enter CS (sleep).
6. Its your turn now.
7. I dont want CS.
## OUTPUT
Starting 2 processes (threads) ...
1: want CS
0: want CS
1: in CS0
1: done CS
1: want CS
0: in CS0
0: done CS
0: want CS
1: in CS1
1: done CS
1: want CS
0: in CS1
0: done CS
1: in CS2
0: want CS
1: done CS
1: want CS
0: in CS2
0: done CS
0: want CS
0: in CS3
0: done CS
1: in CS3
1: done CS

See Main.java for code, and repl.it for output.

references

About

Dekker's algorithm is the first known correct solution to the mutual exclusion problem in concurrent programming.

Topics

Resources

License

Stars

Watchers

Forks

Languages