------------------------------------------------------------------------------- -- Mutual exclusion protocol 3b_c_p3 -- (3 bits, complex conditions, starvation-free) -- generated automatically in [Bar-David-Taubenfeld-03] ------------------------------------------------------------------------------- module mutex_3b_c_p3 (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 ; * b := j ; * while i = 0 xor b != A[b] do * 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_b, b:Nat in j := 1 - i; loop NCS (i); A (Write, i, 1 of Nat, i); B (Write, Nat (j), i); loop L in B (Read, ?b, i); A (Read, b of Pid, ?a_b, i); if not ((i == 0) xor (b != a_b)) then break L end if 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