tarray_of_channels.nim 610 B

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