File: ex_3c.pml

package info (click to toggle)
spin 6.4.5%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,636 kB
  • ctags: 2,878
  • sloc: ansic: 40,035; yacc: 996; makefile: 37; sh: 5
file content (29 lines) | stat: -rw-r--r-- 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
}