added system.onThreadCreation feature for safe thread local storage initializations

This commit is contained in:
Andreas Rumpf 2017-01-18 13:41:55 +01:00
commit 61937974e2
3 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,22 @@
discard """
output: '''some string here'''
"""
var
someGlobal: string = "some string here"
perThread {.threadvar.}: string
proc setPerThread() =
{.gcsafe.}:
deepCopy(perThread, someGlobal)
proc foo() {.thread.} =
echo perThread
proc main =
onThreadCreation setPerThread
var t: Thread[void]
createThread[void](t, foo)
t.joinThread()
main()