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 forcommunication.
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.IwanttoenterCS.
2.IfyouwantCStoo ...
3a. Ifitsmyturn, retry2.4a. Ifitsyourturn, idontwanttoenter.
4b. Iwaitforyouturntocomplete.
4c. Inowwanttoenter, retry2.5.IenterCS (sleep).
6.Itsyourturnnow.
7.IdontwantCS.## 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