blob: 776f8af60045381ac085da0fb222276b832d4543 (
plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
procedure LockingExample();
implementation LockingExample()
{
var x: int;
var y: int;
var held: int;
start:
held := 0;
x := 0;
goto LoopHead;
LoopHead:
// Lock
held := held + 6;
assert held == 0;
held := 1;
y := x;
goto UnlockNow, LoopEnd;
UnlockNow:
// Unlock
assert held == 1;
held := 0;
x := x + 1;
goto LoopEnd;
LoopEnd:
goto ContinueIteration, EndIteration;
ContinueIteration:
assume x != y;
goto LoopHead;
EndIteration:
assume x == y;
goto AfterLoop;
AfterLoop:
// Unlock
assert held == 1;
held := 0;
return;
}
|