------------------------------------------------------------------------------- -- Mutual exclusion protocol 2b_p1 -- (2 bits, simple conditions, single-writer, deadlock-free) -- generated automatically in [Bar-David-Taubenfeld-03] ------------------------------------------------------------------------------- module mutex_2b_p1 (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] := 1 ; * while A[j] = 1 do * A[i] := j ; * while A[0] = i do * end while ; * A[i] := 1 * 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_j: Nat in j := 1 - i; loop NCS (i); A (Write, i, 1 of Nat, i); loop L1 in A (Read, j, ?a_j, i); if a_j != 1 then break L1 end if; A (Write, i, Nat (j), i); loop L2 in A (Read, 0 of Pid, ?a_0, i); if a_0 != i then break L2 end if end loop; A (Write, i, 1 of Nat, i) 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