-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d48a7d
commit 13b8ad5
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
field turn: Int | ||
field flagL: Bool | ||
field flagR: Bool | ||
|
||
|
||
inv petersonInv() { | ||
|
||
} | ||
|
||
proc acquireL(root: Ref) | ||
requires exists b1: Bool, b2: Bool, i: Int :: | ||
own(root, turn, i, 1.0) && | ||
own(root, flagL, b1, 1.0) && | ||
own(root, flagR, b2, 1.0) | ||
{ | ||
root.flagL := true; | ||
root.turn := 1; | ||
|
||
var flag : Bool := root.flagR; | ||
var currTurn : Int := root.turn; | ||
|
||
while(flag == false && currTurn != 2) | ||
invariant exists b1: Bool, b2: Bool, i: Int :: | ||
own(root, turn, i, 1.0) && | ||
own(root, flagL, b1, 1.0) && | ||
own(root, flagR, b2, 1.0) | ||
{ | ||
flag := root.flagR; | ||
currTurn := root.turn; | ||
} | ||
|
||
// Secure section | ||
} | ||
|
||
proc exitL(root: Ref) | ||
requires exists b1: Bool :: | ||
own(root, flagL, b1, 1.0) | ||
{ | ||
root.flagL := false; | ||
} | ||
|
||
proc acquireR(root: Ref) | ||
requires exists i: Int, b1: Bool, b2: Bool :: | ||
own(root, turn, i, 1.0) && | ||
own(root, flagL, b1, 1.0) && | ||
own(root, flagR, b2, 1.0) | ||
{ | ||
root.flagR := true; | ||
root.turn := 2; | ||
|
||
var flag : Bool := root.flagL; | ||
var currTurn : Int := root.turn; | ||
|
||
while(flag == false && currTurn != 1) | ||
invariant exists b1: Bool, b2: Bool, i: Int :: | ||
own(root, turn, i, 1.0) && | ||
own(root, flagL, b1, 1.0) && | ||
own(root, flagR, b2, 1.0) | ||
{ | ||
flag := root.flagL; | ||
currTurn := root.turn; | ||
} | ||
|
||
// Secure section | ||
} | ||
|
||
proc exitR(root: Ref) | ||
requires exists b2: Bool :: | ||
own(root, flagR, b2, 1.0) | ||
{ | ||
root.flagR := false; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters