mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-28 18:24:01 +00:00
onThreadDestruction feature added to Nim's threading model
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user