summaryrefslogtreecommitdiff
path: root/Test/civl/lock2.bpl
diff options
context:
space:
mode:
authorGravatar qadeer <qadeer@microsoft.com>2015-04-22 09:26:56 -0700
committerGravatar qadeer <qadeer@microsoft.com>2015-04-22 09:26:56 -0700
commit4c6dd519143fdbc8ecada56d58103d098c6bd18c (patch)
treeabdbf5f883d31236a221a5b95f5f0364e75caf36 /Test/civl/lock2.bpl
parent95a9ed0282811aa2bc3170f41b8b63508918b28e (diff)
renamed og to civl
Diffstat (limited to 'Test/civl/lock2.bpl')
-rw-r--r--Test/civl/lock2.bpl63
1 files changed, 63 insertions, 0 deletions
diff --git a/Test/civl/lock2.bpl b/Test/civl/lock2.bpl
new file mode 100644
index 00000000..4809a8f5
--- /dev/null
+++ b/Test/civl/lock2.bpl
@@ -0,0 +1,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; }|;