summaryrefslogtreecommitdiff
path: root/Chalice/tests/general-tests/prog4.chalice
blob: 3c655c718d06f5bc5038b9f879361e3520241158 (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
class LoopTargets {
  method M() returns (y) {
    y := 0
    while (y < 100) { y := y + 1 }
    assert y == 0  // error (139)
  }
  method N() returns (t: LoopTargets)
    lockchange t
  {
    t := new LoopTargets
    share t
    acquire t
    var s := true
    while (s) 
      lockchange t 
    {
      release t  // error: loop invariant does not say holds(t) (252)
      s := false
    }
  }
  method P() {
    var t := new LoopTargets
    share t
    acquire t
    var s := true
    while (s) 
      invariant acc(t.mu) && waitlevel == t.mu
      lockchange t
    {
      release t  // error: loop invariant does not say holds(t) (414)
      acquire t
      s := false
    }
    release t
  }
  method Q() {
    var t := new LoopTargets
    share t
    acquire t
    var s := true
    while (s) 
      invariant rd(t.mu)
      invariant holds(t) && waitlevel == t.mu
      lockchange t
    {
      release t
      acquire t
      s := false
    }
    assert holds(t)  // there we are
    release t
  }
}