Created
January 13, 2020 15:35
-
-
Save treeform/b8abfeae9038ba64af35724e7b1a0386 to your computer and use it in GitHub Desktop.
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
# createThread then .add -> crash | |
# .add then createThread -> some threads dont run | |
# pre .add all threads -> works 100% | |
import locks | |
var | |
thr: seq[Thread[void]] | |
L: Lock | |
proc threadFunc() {.thread.} = | |
acquire(L) | |
echo "exit" | |
release(L) | |
initLock(L) | |
# # crashes: | |
# for i in 0 ..< 5: | |
# var t: Thread[void] | |
# createThread(t, threadFunc) | |
# thr.add t | |
# # strange behavior, not all threads run: | |
# for i in 0 ..< 5: | |
# var t: Thread[void] | |
# thr.add t | |
# createThread(t, threadFunc) | |
for i in 0 ..< 5: | |
var t: Thread[void] | |
thr.add t | |
for i in 0 ..< 5: | |
createThread(thr[i], threadFunc) | |
joinThreads(thr) | |
echo "exit final" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment