onThreadDestruction feature added to Nim's threading model

This commit is contained in:
Andreas Rumpf
2017-01-24 12:07:38 +01:00
parent 0ead17bf0e
commit eb96eaa5c2
2 changed files with 38 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
discard """
output: '''some string here'''
output: '''some string here
dying some string here'''
"""
var
@@ -10,11 +11,15 @@ proc setPerThread() =
{.gcsafe.}:
deepCopy(perThread, someGlobal)
proc threadDied() {.gcsafe} =
echo "dying ", perThread
proc foo() {.thread.} =
echo perThread
proc main =
onThreadCreation setPerThread
onThreadDestruction threadDied
var t: Thread[void]
createThread[void](t, foo)
t.joinThread()