diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-01-18 13:41:55 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-01-18 13:41:55 +0100 |
commit | 61937974e2a7fcf3ff6427510f793c4b580f1b62 (patch) | |
tree | 3cc11bc32a1bf760a9715d62b1640a66dd08c78b /tests/threads/tonthreadcreation.nim | |
parent | 2f08fdf6238baefca633ebbd2776ec366288e96d (diff) | |
download | Nim-61937974e2a7fcf3ff6427510f793c4b580f1b62.tar.gz |
added system.onThreadCreation feature for safe thread local storage initializations
Diffstat (limited to 'tests/threads/tonthreadcreation.nim')
-rw-r--r-- | tests/threads/tonthreadcreation.nim | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/threads/tonthreadcreation.nim b/tests/threads/tonthreadcreation.nim new file mode 100644 index 000000000..c96e86d4d --- /dev/null +++ b/tests/threads/tonthreadcreation.nim @@ -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() |