summaryrefslogtreecommitdiff
path: root/Test/og/lock.bpl
blob: 4a6e002db800e5e366e50c58c8d9274992bea54f (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
52
53
54
55
56
57
58
59
60
61
var {:phase 2} b: bool;

procedure {:yields} {:phase 2} main()
{
    while (*)
    {
        yield;

        async call Customer();

        yield;
    }
}

procedure {:yields} {:phase 2} Customer()
{
    while (*) 
    {
    	yield;

        call Enter();

    	yield;

    	call Leave();

        yield;
    }

    yield;
}

procedure {:yields} {:phase 1,2} Enter() 
ensures {:atomic} |{ A: assume !b; b := true; return true; }|;
{
    var status: bool;
    yield;
    L: 
        call status := CAS(false, true);
	yield;
        goto A, B;

    A: 
        assume status;
	yield;
	return;

    B:
        assume !status;
	goto L;
}

procedure {:yields} {:phase 0,2} CAS(prev: bool, next: bool) returns (status: bool);
ensures {:atomic} |{ 
A: goto B, C; 
B: assume b == prev; b := next; status := true; return true; 
C: status := false; return true; 
}|;

procedure {:yields} {:phase 0,2} Leave();
ensures {:atomic} |{ A: b := false; return true; }|;