tonthreadcreation.nim 489 B

123456789101112131415161718192021222324252627
  1. discard """
  2. disabled: i386
  3. matrix: "--mm:refc; --mm:orc --deepcopy:on"
  4. output: '''some string here
  5. dying some string here'''
  6. """
  7. var
  8. someGlobal: string = "some string here"
  9. perThread {.threadvar.}: string
  10. proc threadDied() {.gcsafe.} =
  11. echo "dying ", perThread
  12. proc foo() {.thread.} =
  13. onThreadDestruction threadDied
  14. {.gcsafe.}:
  15. deepCopy(perThread, someGlobal)
  16. echo perThread
  17. proc main =
  18. var t: Thread[void]
  19. createThread[void](t, foo)
  20. t.joinThread()
  21. main()