tonthreadcreation.nim 426 B

12345678910111213141516171819202122232425
  1. discard """
  2. output: '''some string here
  3. dying some string here'''
  4. """
  5. var
  6. someGlobal: string = "some string here"
  7. perThread {.threadvar.}: string
  8. proc threadDied() {.gcsafe.} =
  9. echo "dying ", perThread
  10. proc foo() {.thread.} =
  11. onThreadDestruction threadDied
  12. {.gcsafe.}:
  13. deepCopy(perThread, someGlobal)
  14. echo perThread
  15. proc main =
  16. var t: Thread[void]
  17. createThread[void](t, foo)
  18. t.joinThread()
  19. main()