File: ex_3c.pml

package info (click to toggle)
spin 6.5.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,512 kB
  • sloc: ansic: 39,876; yacc: 1,021; makefile: 58; sh: 8
file content (29 lines) | stat: -rwxr-xr-x 478 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// http://spinroot.com/spin/Doc/Exercises.html
// faulty mutual exclusion algorithm

byte cnt
byte x, y, z

active [2] proctype user()
{	byte me = _pid+1			// 1 or 2

L1:	x = me
	if
	:: (y != 0 && y != me) -> goto L1	// try again
	:: (y == 0 || y == me)
	fi
	z = me
	if
	:: (x != me)  -> goto L1		// try again
	:: (x == me)
	fi
	y = me
	if
	:: (z != me) -> goto L1			// try again
	:: (z == me)
	fi					// success
	cnt++
	assert(cnt == 1)			// critical section
	cnt--
	goto L1
}