tgc_unsafe.nim 600 B

123456789101112131415161718192021222324252627282930313233
  1. discard """
  2. errormsg: "'consumer' is not GC-safe"
  3. line: 19
  4. """
  5. # bug #2257
  6. import threadpool
  7. type StringChannel = Channel[string]
  8. var channels: array[1..3, StringChannel]
  9. type
  10. MyObject[T] = object
  11. x: T
  12. var global: MyObject[string]
  13. var globalB: MyObject[float]
  14. proc consumer(ix : int) {.thread.} =
  15. echo channels[ix].recv() ###### not GC-safe: 'channels'
  16. echo global
  17. echo globalB
  18. proc main =
  19. for ix in 1..3: channels[ix].open()
  20. for ix in 1..3: spawn consumer(ix)
  21. for ix in 1..3: channels[ix].send("test")
  22. sync()
  23. for ix in 1..3: channels[ix].close()
  24. when true:
  25. main()