-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user-definable auxiliary procedures to init/exit (#164)
* Add user-definable auxiliary procedures to init/exit * Fix GC safety perventing compilation * Add tests * Remove accidentally redundant test * Fix nil checks - check if proc is nil, not pointer to proc * Auxiliary Proc type fixes, removed pointer indirection * Remove typo * Fix URL in comment
- Loading branch information
Showing
5 changed files
with
45 additions
and
2 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,18 @@ | ||
import | ||
std/[atomics, os], | ||
../weave | ||
|
||
var count: Atomic[int] | ||
|
||
proc increment() = count += 1 | ||
proc decrement() = count -= 1 | ||
|
||
const ThreadsToLaunch = 8 # Arbitrary value | ||
|
||
putEnv("WEAVE_NUM_THREADS", $ThreadsToLaunch) | ||
|
||
init(Weave, increment) | ||
syncRoot(Weave) | ||
doAssert(count.load == ThreadsToLaunch - 1) | ||
exit(Weave, decrement) | ||
doAssert(count.load == 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
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