------------------------------------------------------------------------------- -- Mutual exclusion protocol 3b_p2 -- (3 bits, simple conditions, deadlock-free) -- generated automatically in [Bar-David-Taubenfeld-03] ------------------------------------------------------------------------------- module mutex_3b_p2 (ARCH_3B) 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] := 1 ; * while B != A[j] do * while A[B] = i do * B := A[0] * end while * end while ; * critical section ; * A[i] := 0 * end loop *) process P [NCS:Pid, CS:Access, A, B:Operation] (i: Pid) is var j: Pid, a_0, a_j, a_b, b:Nat in j := 1 - i; loop NCS (i); A (Write, i, 1 of Nat, i); loop L1 in B (Read, ?b, i); A (Read, j, ?a_j, i); if b == a_j then break L1 end if; loop L2 in B (Read, ?b, i); A (Read, b of Pid, ?a_b, i); if a_b != i then break L2 end if; A (Read, 0 of Pid, ?a_0, i); B (Write, a_0, 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, B:Operation, MU:Latency] is Arch_3b [NCS, CS, A, B, MU] end process end module