summary refs log tree commit diff stats
path: root/tests/threads/tonthreadcreation.nim
blob: f588a21c90f21eb29f2afcc0ee9bed871cd22592 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
discard """
  output: '''some string here
dying some string here'''
"""

var
  someGlobal: string = "some string here"
  perThread {.threadvar.}: string

proc threadDied() {.gcsafe.} =
  echo "dying ", perThread

proc foo() {.thread.} =
  onThreadDestruction threadDied
  {.gcsafe.}:
    deepCopy(perThread, someGlobal)
  echo perThread

proc main =
  var t: Thread[void]
  createThread[void](t, foo)
  t.joinThread()

main()