summaryrefslogtreecommitdiff
path: root/Chalice/examples/prog4.chalice
blob: 655c5815e37186202b5bfaec9cf142d609fe6388 (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
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) {
      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) && maxlock == t.mu
    {
      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) && maxlock == t.mu
    {
      release t
      acquire t
      s := false
    }
    assert holds(t)  // there we are
    release t
  }
}