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

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 == 0; b := 1; return true; }|;
{
    var _old, curr: int;
    yield;
    while (true) { 
        call _old := CAS(0, 1);
	yield;
        if (_old == 0) {
	    break;
	}
	while (true) {
	    call curr := Read();
	    yield;
	    if (curr == 0) {
	        break;
	    }
	}
	yield;
    }
    yield;
}

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

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