- Open a terminal and run server_critical_section.py
- Then open another terminal and run client_processes.py
This is an implementation of Stable Algorithm for Mutual Exclusion (processes concurrence) in a distributed system, proposed by Edsger W. Dijkstra in 1974.
This implementation does not link processes trough socket, for this demonstration, processes are stored in a simple list.
When need_access_to_critical_section Do
If (i = 0) then
When ( L = S ) Do
go_to_critical_section();
S = (L + 1) mod K;
EndWhen
Else
When ( L <> S ) Do
go_to_critical_section();
S = L;
EndWhen
EndIf
EndWhen
Since processes are stored in a list, we can skip a some steps.
- Synchronus comunication
- Ring logic topology
- Solution consider N processes, ranged from 0 to N - 1
Variables used:
- i = Process id
- S = Status of process i
- L = Last process status
- K = Constant bigger or iqual to N
In the source code, some variables and methods are defined but not used, they remains for future implementations and changes.
- Socket Server with Multiple Clients | Multithreading | Python
- Python Multithreading Example: Create Socket Server with Multiple Clients
- Socket Programming with Multi-threading in Python
- Socket Programming in Python (Guide)
- Real Python
- Self-Stabilizing Mutual Exclusion Dijkstra Algorithm
- Proof of Self-Stabilizing Mutual Exclusion Dijkstra Algorithm