added system.onThreadCreation feature for safe thread local storage initializations
This commit is contained in:
parent
2f08fdf623
commit
61937974e2
3 changed files with 54 additions and 0 deletions
22
tests/threads/tonthreadcreation.nim
Normal file
22
tests/threads/tonthreadcreation.nim
Normal 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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue