Skip to content

Commit

Permalink
Simplify atomic syntax.
Browse files Browse the repository at this point in the history
Instead of having two atomic syntaxes:

```
<x = y++>;  // single atomic action
<{ x = y; y = y + 1; }>;  // multiple atomic actions
```

We now have a single syntax:

```
<| x = y++; |>  // single atomic action
<| x = y; y = y + 1; |>  // multiple atomic actions
```

Note that the new syntax behaves exactly like a block: it requires
semicolons to terminate inner actions, but has no semicolon at the
end.

This is in preparation for making atomic syntax richer.
  • Loading branch information
MattWindsor91 committed Feb 13, 2017
1 parent cc137e1 commit 6f99ae3
Show file tree
Hide file tree
Showing 34 changed files with 203 additions and 206 deletions.
6 changes: 3 additions & 3 deletions Examples/Errors/local_in_shared_context.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ thread int s; // The thread's current view of serving.
*/
method lock() {
{| emp |}
<t = s++>; // <-- Thread-local in shared context
<| t = s++; |> // <-- Thread-local in shared context
{| holdTick(t) |}
do {
{| holdTick(t) |}
<s = serving>;
<| s = serving; |>
{| if s == t then holdLock() else holdTick(t) |}
} while (s != t);
{| holdLock() |}
Expand All @@ -27,7 +27,7 @@ method lock() {
*/
method unlock() {
{| holdLock() |}
<serving++>;
<| serving++; |>
{| emp |}
}

Expand Down
6 changes: 3 additions & 3 deletions Examples/Errors/shared_in_local_context.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ thread int s; // The thread's current view of serving.
*/
method lock() {
{| emp |}
<ticket = ticket++>; // <-- shared in local context
<| ticket = ticket++; |> // <-- shared in local context
{| holdTick(t) |}
do {
{| holdTick(t) |}
<s = serving>;
<| s = serving; |>
{| if s == t then holdLock() else holdTick(t) |}
} while (s != t);
{| holdLock() |}
Expand All @@ -27,7 +27,7 @@ method lock() {
*/
method unlock() {
{| holdLock() |}
<serving++>;
<| serving++; |>
{| emp |}
}

Expand Down
10 changes: 5 additions & 5 deletions Examples/Fail/petersonArrayBadTurns.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ view holdLock(int me); // 'me' holds the lock.
*/
method lock() {
{| flagDown(i) |}
<flag[i] = true>;
<| flag[i] = true; |>
{| flagUp(i) |}
<turn = (i + 1) % 2>; // oops!
<| turn = (i + 1) % 2; |> // oops!
{| waiting(i) |}
do {
{| waiting(i) |}
<oFlag = flag[(i + 1) % 2]>;
<| oFlag = flag[(i + 1) % 2]; |>
{| if (oFlag) then waiting(i) else holdLock(i) |}
<oTurn = turn>;
<| oTurn = turn; |>
{| if (oFlag && oTurn == i) then waiting(i) else holdLock(i) |}
} while (oFlag && (oTurn == i));
{| holdLock(i) |}
Expand All @@ -46,7 +46,7 @@ method lock() {
*/
method unlock() {
{| holdLock(i) |}
<flag[i] = false>;
<| flag[i] = false; |>
{| flagDown(i) |}
}

Expand Down
20 changes: 10 additions & 10 deletions Examples/Fail/petersonBadTurns.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ view bHoldLock(); // B holds the lock.
*/
method lockA() {
{| aFlagDown() |}
<aFlag = (true)>;
<| aFlag = (true); |>
{| aFlagUp() |}
<turn = 2>; // oops!
<| turn = 2; |> // oops!
{| aWaiting() |}
do {
{| aWaiting() |}
<oFlag = bFlag>;
<| oFlag = bFlag; |>
{| if (oFlag) then aWaiting() else aHoldLock() |}
<oTurn = turn>;
<| oTurn = turn; |>
{| if (oFlag && oTurn == 1) then aWaiting() else aHoldLock() |}
} while (oFlag && (oTurn == 1));
{| aHoldLock() |}
Expand All @@ -49,7 +49,7 @@ method lockA() {
*/
method unlockA() {
{| aHoldLock() |}
<aFlag = (false)>;
<| aFlag = (false); |>
{| aFlagDown() |}
}

Expand All @@ -58,15 +58,15 @@ method unlockA() {
*/
method lockB() {
{| bFlagDown() |}
<bFlag = true>;
<| bFlag = true; |>
{| bFlagUp() |}
<turn = 1>; // oops!
<| turn = 1; |> // oops!
{| bWaiting() |}
do {
{| bWaiting() |}
<oFlag = aFlag>;
<| oFlag = aFlag; |>
{| if (oFlag) then bWaiting() else bHoldLock() |}
<oTurn = turn>;
<| oTurn = turn; |>
{| if (oFlag && oTurn == 2) then bWaiting() else bHoldLock() |}
} while (oFlag && (oTurn == 2));
{| bHoldLock() |}
Expand All @@ -77,7 +77,7 @@ method lockB() {
*/
method unlockB() {
{| bHoldLock() |}
<bFlag = false>;
<| bFlag = false; |>
{| bFlagDown() |}
}

Expand Down
6 changes: 3 additions & 3 deletions Examples/Fail/ticketLockBad.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ thread int s; // The thread's current view of serving.
*/
method lock() {
{| emp |}
<t = ticket++>;
<| t = ticket++; |>
{| holdTick(t) |}
do {
{| holdTick(t) |}
<s = serving>;
<| s = serving; |>
{| if s == t then holdLock() else holdTick(t) |}
} while (s != t);
{| holdLock() |}
Expand All @@ -27,7 +27,7 @@ method lock() {
*/
method unlock() {
{| holdLock() |}
<serving++>;
<| serving++; |>
{| emp |}
}

Expand Down
6 changes: 3 additions & 3 deletions Examples/Fail/ticketLockBad2.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ thread int s; // The thread's current view of serving.
*/
method lock() {
{| emp |}
<t = ticket++>;
<| t = ticket++; |>
{| holdTick(t) |}
do {
{| holdTick(t) |}
<s = serving>;
<| s = serving; |>
{| if s == t then holdLock() else holdTick(t) |}
} while (s != t);
{| holdLock() |}
Expand All @@ -27,7 +27,7 @@ method lock() {
*/
method unlock() {
{| holdLock() |}
<serving++>;
<| serving++; |>
{| emp |}
}

Expand Down
6 changes: 3 additions & 3 deletions Examples/Fail/ticketLockFlippedLoop.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ thread int s; // The thread's current view of serving.
*/
method lock() {
{| emp |}
<t = ticket++>;
<| t = ticket++; |>
{| holdTick(t) |}
do {
{| holdTick(t) |}
<s = serving>;
<| s = serving; |>
{| if s == t then holdLock() else holdTick(t) |}
} while (s == t);
{| holdLock() |}
Expand All @@ -27,7 +27,7 @@ method lock() {
*/
method unlock() {
{| holdLock() |}
<serving++>;
<| serving++; |>
{| emp |}
}

Expand Down
6 changes: 3 additions & 3 deletions Examples/FailGH/ticketLockFlippedIf.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ method newLock() {
{| emp |}
ret = %{new Lock};
{| newLock(ret) |}
<%{[|ret|].ticket := 0; [|ret|].serving := 0}>;
<| %{[|ret|].ticket := 0; [|ret|].serving := 0}; |>
{| isLock(ret) |}
}

method lock(Lock x) {
{| isLock(x) |}
t = %{ [|x|].ticket };
<%{ [|x|].ticket := [|x|].ticket + 1 }>;
<| %{ [|x|].ticket := [|x|].ticket + 1 }; |>
{| holdTick(x, t) |}
do {
{| holdTick(x, t) |}
Expand All @@ -40,7 +40,7 @@ method lock(Lock x) {

method unlock(Lock x) {
{| holdLock(x) |}
<%{[|x|].serving := [|x|].serving + 1}>;
<| %{[|x|].serving := [|x|].serving + 1}; |>
{| isLock(x) |}
}

Expand Down
8 changes: 4 additions & 4 deletions Examples/Pass/arc.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ thread int c;

// Assumption: clone() cannot be called when there are no references
method clone() {
{| arc() |} < count++ >; {| arc() * arc() |}
{| arc() |} <| count++; |> {| arc() * arc() |}
}

// Try to prove that print() when holding a reference is always valid
// i.e. free can never be true when {| arc() |} is held
method print() {
{| arc() |}
<f = free>;
<| f = free; |>
{| arc() * specialViewForFree(f) |}
// Test for disposal
if (f == true) {
Expand All @@ -28,11 +28,11 @@ method print() {

method drop() {
{| arc() |}
< c = count-- >;
<| c = count--; |>
{| specialViewForC(c) |}
if (c == 1) {
{| noCnt() |}
<free = (true)>;
<| free = true; |>
{| emp |}
}
{| emp |}
Expand Down
20 changes: 10 additions & 10 deletions Examples/Pass/arc2.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@ view error();
constraint error() -> false;

method clone() {
{| arc() |}
< count++ >;
{| arc() |}
<| count++ ; |>
{| arc() * arc() |}
}

method print() {
{| arc() |}
<f = free>;
<| f = free; |>
{| if f == true then error() else arc() |}
if (f == true) {
{| error() |}
{| error() |}
}
{| arc() |}
}

method drop() {
{| arc() |}
< c = count-- >;
<| c = count--; |>
{| countCopy(c) |}
if (c == 1) {
{| countCopy(1) |}
<free = (true)>;
<| free = true; |>
{| emp |}
}
{| emp |}
}

constraint iter[n] arc() ->
constraint iter[n] arc() ->
n > 0 => (free == false && n <= count);

constraint countCopy(c) ->
constraint countCopy(c) ->
c == 1 => (free == false && count == 0);

constraint countCopy(m) * countCopy(n) ->
(m != 1) || (n != 1);
constraint countCopy(m) * countCopy(n) ->
(m != 1) || (n != 1);

2 changes: 1 addition & 1 deletion Examples/Pass/multicounter.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ method multiIncrement() {
{| count(t) |}
t=t+1;
{| count(t-1) |}
<counter++>;
<| counter++; |>
{| count(t) |}
} while (t != 10);
{| count(10) |}
Expand Down
20 changes: 10 additions & 10 deletions Examples/Pass/peterson.cvf
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ view bHoldLock(); // B holds the lock.
*/
method lockA() {
{| aFlagDown() |}
<aFlag = true>;
<| aFlag = true; |>
{| aFlagUp() |}
<turn = 1>;
<| turn = 1; |>
{| aWaiting() |}
do {
{| aWaiting() |}
<oFlag = bFlag>;
<| oFlag = bFlag; |>
{| if (oFlag) then aWaiting() else aHoldLock() |}
<oTurn = turn>;
<| oTurn = turn; |>
{| if (oFlag && oTurn == 1) then aWaiting() else aHoldLock() |}
} while (oFlag && (oTurn == 1));
{| aHoldLock() |}
Expand All @@ -55,7 +55,7 @@ method lockA() {
*/
method unlockA() {
{| aHoldLock() |}
<aFlag = false>;
<| aFlag = false; |>
{| aFlagDown() |}
}

Expand All @@ -64,15 +64,15 @@ method unlockA() {
*/
method lockB() {
{| bFlagDown() |}
<bFlag = true>;
<| bFlag = true; |>
{| bFlagUp() |}
<turn = 2>;
<| turn = 2; |>
{| bWaiting() |}
do {
{| bWaiting() |}
<oFlag = aFlag>;
<| oFlag = aFlag; |>
{| if (oFlag) then bWaiting() else bHoldLock() |}
<oTurn = turn>;
<| oTurn = turn; |>
{| if (oFlag && oTurn == 2) then bWaiting() else bHoldLock() |}
} while (oFlag && (oTurn == 2));
{| bHoldLock() |}
Expand All @@ -83,7 +83,7 @@ method lockB() {
*/
method unlockB() {
{| bHoldLock() |}
<bFlag = false>;
<| bFlag = false; |>
{| bFlagDown() |}
}

Expand Down
Loading

0 comments on commit 6f99ae3

Please sign in to comment.