Szymanski算法是由計算機科學家Boleslaw Szymanski博士設計的互斥算法,它具有許多有利的性質,包括線性等待,和擴展解決了Leslie Lamport發布的開放問題是否存在每個過程具有恆定通信位數的算法,其滿足Lamport所構想的每個合理的公平性和容錯性要求(Lamport的解決方案使用n因子通信變數與Szymanski的5)。
基本介紹
- 中文名:Szymanski算法
- 外文名:Szymański's algorithm
#Entry protocol
flag[self] ← 1
await(all flag[1..N] ∈ {0, 1, 2})
flag[self] ← 3 #Standing in doorway
if any flag[1..N] = 1:
flag[self] ← 2 #Waiting for other processes to enter await(any flag[1..N] = 4)
flag[self] ← 4 #The door is closed
await(all flag[1..self-1] ∈ {0, 1})
await(all flag[self+1..N] ∈ {0, 1, 4}) #Ensure everyone in the waiting room has #realized that the door is supposed to be closed
flag[self] ← 0