summaryrefslogtreecommitdiff
path: root/Test/og/lock.bpl
blob: 9341591f780a066ede6d7f9802fd9ad7b19c2d44 (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
// RUN: %boogie -noinfer -typeEncoding:m -useArrayTheory "%s" > "%t"
// RUN: %diff "%s.expect" "%t"
var {:layer 0,2} b: bool;

procedure {:yields} {:layer 2} main()
{
    yield;
    while (*)
    {
        async call Customer();
        yield;
    }
    yield;
}

procedure {:yields} {:layer 2} Customer()
{
    yield;
    while (*) 
    {
        call Enter();
    	yield;
    	call Leave();
        yield;
    }
    yield;
}

procedure {:yields} {:layer 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} {:layer 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} {:layer 0,2} Leave();
ensures {:atomic} |{ A: b := false; return true; }|;