diff --git a/Concurrent Systems/notes/3a - Hardware primitives & Lamport Bakery algorithm.md b/Concurrent Systems/notes/3a - Hardware primitives & Lamport Bakery algorithm.md index 155d6b4..e55759d 100644 --- a/Concurrent Systems/notes/3a - Hardware primitives & Lamport Bakery algorithm.md +++ b/Concurrent Systems/notes/3a - Hardware primitives & Lamport Bakery algorithm.md @@ -141,6 +141,25 @@ lock(i) := unlock(i) := MY_TURN[i] <- 0 + + + + + +lock(i) := + FLAG[i] <- up + max_turn <- max{MY_TURN[1],...,MY_TURN[n]} + if max_turn > 2n then + + + + FLAG[i] <- down + forall j != i + wait FLAG[j] = down + wait (MY_TURN[j] = 0 OR ⟨MY_TURN[i],i⟩ < ⟨MY_TURN[j],j⟩) + +unlock(i) := + MY_TURN[i] <- 0 ``` Se il ticket number è minore si ottiene l'accesso, se il ticket number è uguale, allora si vede il process ID minore.