tarray_of_channels.nim 526 B

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