------------------------------------------------------------------------------- -- Mutual exclusion protocol 2b_p3 -- (2 bits, simple conditions, single-writer, deadlock-free) -- generated automatically in [Bar-David-Taubenfeld-03] ------------------------------------------------------------------------------- module mutex_2b_p3 (ARCH_2B) is !nat_bits 2 -- use 2 bits to store natural numbers (* * Process P (i) competing for the access to critical section * where i = 0..1, j = 1 - i * * loop * non critical section ; * A[i] := i ; * while A[0] = i do * A[i] := 1 ; * while A[1] = j do * A[i] := 0 * end while ; * end while ; * critical section ; * A[i] := 0 * end loop *) process P [NCS:Pid, CS:Access, A:Operation] (i: Pid) is var j: Pid, a_0, a_1:Nat in j := 1 - i; loop NCS (i); A (Write, i, Nat (i), i); loop L1 in A (Read, 0 of Pid, ?a_0, i); if a_0 != i then break L1 end if; A (Write, i, 1 of Nat, i); loop L2 in A (Read, 1 of Pid, ?a_1, i); if a_1 != j then break L2 end if; A (Write, i, 0 of Nat, i) end loop end loop; CS (Enter, i); CS (Leave, i); A (Write, i, 0 of Nat, i) end loop end var end process ------------------------------------------------------------------------------- process Main [NCS:Pid, CS:Access, A:Operation, MU:Latency] is Arch_2b [NCS, CS, A, MU] end process end module