-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from septract/bjs-cav
Shared symbols can take thread-locals, and other environment fixes
- Loading branch information
Showing
11 changed files
with
483 additions
and
220 deletions.
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,47 @@ | ||
/* | ||
* Linux-style ticket lock. | ||
*/ | ||
|
||
shared int ticket; // The next ticket to hand out. | ||
shared int serving; // The current ticket holding the lock. | ||
thread int t; // The thread's current ticket. | ||
thread int s; // The thread's current view of serving. | ||
|
||
/* | ||
* Locks the ticket lock. | ||
*/ | ||
method lock() { | ||
{| emp |} | ||
<t = s++>; // <-- Thread-local in shared context | ||
{| holdTick(t) |} | ||
do { | ||
{| holdTick(t) |} | ||
<s = serving>; | ||
{| if s == t then holdLock() else holdTick(t) |} | ||
} while (s != t); | ||
{| holdLock() |} | ||
} | ||
|
||
/* | ||
* Unlocks the ticket lock. | ||
*/ | ||
method unlock() { | ||
{| holdLock() |} | ||
<serving++>; | ||
{| emp |} | ||
} | ||
|
||
view holdTick(int t); | ||
view holdLock(); | ||
|
||
// Invariant | ||
constraint emp -> ticket >= serving; | ||
|
||
// Predicate definitions | ||
constraint holdTick(t) -> ticket > t; | ||
constraint holdLock() -> ticket != serving; | ||
|
||
// Interactions | ||
constraint holdLock() * holdTick(t) -> serving != t; | ||
constraint holdTick(ta) * holdTick(tb) -> ta != tb; | ||
constraint holdLock() * holdLock() -> 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Linux-style ticket lock. | ||
*/ | ||
|
||
shared int ticket; // The next ticket to hand out. | ||
shared int serving; // The current ticket holding the lock. | ||
thread int t; // The thread's current ticket. | ||
thread int s; // The thread's current view of serving. | ||
|
||
/* | ||
* Locks the ticket lock. | ||
*/ | ||
method lock() { | ||
{| emp |} | ||
<ticket = ticket++>; // <-- shared in local context | ||
{| holdTick(t) |} | ||
do { | ||
{| holdTick(t) |} | ||
<s = serving>; | ||
{| if s == t then holdLock() else holdTick(t) |} | ||
} while (s != t); | ||
{| holdLock() |} | ||
} | ||
|
||
/* | ||
* Unlocks the ticket lock. | ||
*/ | ||
method unlock() { | ||
{| holdLock() |} | ||
<serving++>; | ||
{| emp |} | ||
} | ||
|
||
view holdTick(int t); | ||
view holdLock(); | ||
|
||
// Invariant | ||
constraint emp -> ticket >= serving; | ||
|
||
// Predicate definitions | ||
constraint holdTick(t) -> ticket > t; | ||
constraint holdLock() -> ticket != serving; | ||
|
||
// Interactions | ||
constraint holdLock() * holdTick(t) -> serving != t; | ||
constraint holdTick(ta) * holdTick(tb) -> ta != tb; | ||
constraint holdLock() * holdLock() -> 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
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
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
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
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
Oops, something went wrong.