-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
28 changed files
with
843 additions
and
433 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
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
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
count = 0 | ||
|
||
finally count == 2 | ||
|
||
entered = done = [ False, False ] | ||
|
||
def incrementer(self): | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import list | ||
|
||
def BoundedBuffer(size) returns buffer: | ||
buffer = { .buffer: [], .size: size } | ||
|
||
def put(bb, v): | ||
atomically when len(bb->buffer) < bb->size: | ||
bb->buffer = list.append(bb->buffer, v) | ||
bb->buffer += [v,] | ||
|
||
def get(bb) returns next: | ||
atomically when bb->buffer != []: | ||
next = list.head(bb->buffer) | ||
bb->buffer = list.tail(bb->buffer) | ||
next = bb->buffer[0] | ||
del bb->buffer[0] |
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 |
---|---|---|
@@ -1,11 +1,17 @@ | ||
# number of threads in the critical section | ||
in_cs = 0 | ||
invariant in_cs in { 0, 1 } | ||
|
||
def thread(): | ||
while choose({ False, True }): | ||
while choose { False, True }: | ||
# Enter critical section | ||
atomically in_cs += 1 | ||
|
||
# Critical section is here | ||
cs: assert countLabel(cs) == 1 | ||
pass | ||
|
||
# Exit critical section | ||
atomically in_cs -= 1 | ||
|
||
spawn thread() | ||
spawn thread() |
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 |
---|---|---|
@@ -1,11 +1,7 @@ | ||
def thread(): | ||
while True: | ||
# Enter critical section | ||
|
||
# Critical section is here | ||
cs: assert countLabel(cs) == 1 | ||
|
||
# Exit critical section | ||
pass | ||
|
||
spawn thread() | ||
spawn thread() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
from synch import Lock, acquire, release | ||
import synch | ||
|
||
const NTHREADS = 3 | ||
const NTHREADS = 2 | ||
|
||
the_lock = Lock() | ||
in_cs = 0 | ||
invariant in_cs in { 0, 1 } | ||
|
||
lock = synch.Lock() | ||
|
||
def thread(): | ||
while choose({ False, True }): | ||
acquire(?the_lock) | ||
cs: assert countLabel(cs) == 1 | ||
release(?the_lock) | ||
synch.acquire(?lock) | ||
|
||
atomically in_cs += 1 | ||
# Critical section | ||
atomically in_cs -= 1 | ||
|
||
synch.release(?lock) | ||
|
||
for i in {1..NTHREADS}: | ||
spawn thread() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
import list | ||
|
||
def Queue() returns empty: | ||
empty = [] | ||
|
||
def put(q, v): | ||
!q = list.append(!q, v) | ||
!q += [v,] | ||
|
||
|
||
def get(q) returns next: | ||
if !q == []: | ||
next = None | ||
else: | ||
next = list.head(!q) | ||
!q = list.tail(!q) | ||
|
||
next = (!q)[0] | ||
del (!q)[0] |
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.