summaryrefslogtreecommitdiff
path: root/Test/og/lock.bpl
blob: c00560fe8232360b5573f3240774f9c40fafe4aa (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
var {:qed} b: bool;

procedure {:yields} {:entrypoint} main()
{
    while (*)
    {
        async call Customer();
    }
}

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

        call Enter();

    	yield;

    	call Leave();
    }
}

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

    A: 
        assume status;
	yield;
	return;

    B:
        assume !status;
	goto L;
}

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

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