------------------------------------------------------------------------------- -- Mutual exclusion protocol 4b_p2 -- (4 bits, simple conditions, starvation-free) -- generated automatically in [Bar-David-Taubenfeld-03] ------------------------------------------------------------------------------- module mutex_4b_p2 (ARCH_4B) 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 ; * C[i] := i ; * A[1] := 0 ; * A[i] := A[0] ; * while C[j] != A[1] do * end while ; * critical section ; * C[i] := j * end loop *) process P [NCS:Pid, CS:Access, A, C:Operation] (i: Pid) is var j: Pid, a_0, a_1, c_j:Nat in j := 1 - i; loop NCS (i); A (Write, i, 1 of Nat, i); C (Write, i, Nat (i), i); A (Write, 1 of Pid, 0 of Nat, i); A (Read, 0 of Pid, ?a_0, i); A (Write, i, a_0, i); loop L in C (Read, j, ?c_j, i); A (Read, 1 of Pid, ?a_1, i); if c_j == a_1 then break L end if end loop; CS (Enter, i); CS (Leave, i); C (Write, i, Nat (j), i) end loop end var end process ------------------------------------------------------------------------------- process Main [NCS:Pid, CS:Access, A, C:Operation, MU:Latency] is Arch_4b [NCS, CS, A, C, MU] end process end module