summaryrefslogtreecommitdiff
path: root/Test/og/lock2.bpl
blob: 87538a20eb68e336161cd1ddfa3ef23c7e46acc3 (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
62
63
64
65
66
67
68
69
// RUN: %boogie -noinfer -typeEncoding:m -useArrayTheory "%s" > "%t"
// RUN: %diff "%s.expect" "%t"
var {:phase 2} b: int;

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

        async call Customer();

        yield;
    }
}

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

        call Enter();

    	yield;

    	call Leave();

        yield;
    }
}

procedure {:yields} {:phase 1,2} Enter() 
ensures {:atomic} |{ A: assume b == 0; b := 1; return true; }|;
{
    var _old, curr: int;
    yield;
    while (true) { 
    	yield;
        call _old := CAS(0, 1);
	yield;
        if (_old == 0) {
	    return;
	}
	while (true) {
	    yield;
	    call curr := Read();
	    yield;
	    if (curr == 0) {
	        break;
	    }
	}
    }
}

procedure {:yields} {:phase 0,2} Read() returns (val: int);
ensures {:atomic} |{ A: val := b; return true; }|;

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

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