------------------------------------------------------------------------------- -- Mutual exclusion protocol 3b_c_p1 -- (3 bits, complex conditions, starvation-free) -- generated automatically in [Bar-David-Taubenfeld-03]. -- The "while" loop condition was rewritten (without any semantic change) -- such that the code of the protocol becomes symmetric. ------------------------------------------------------------------------------- module mutex_3b_c_p1 (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 A[i] = A[j] and b = j 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_i, a_j, b:Nat in j := 1 - i; loop NCS (i); A (Write, i, 1 of Nat, i); B (Write, Nat (j), i); loop L in A (Read, i, ?a_i, i); A (Read, j, ?a_j, i); B (Read, ?b, i); if not ((a_i == a_j) and (b == j)) 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