tarray_of_channels.nim 630 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. disabled: "openbsd"
  12. """
  13. # bug #2257
  14. import threadpool
  15. type StringChannel = Channel[string]
  16. var channels: array[1..3, StringChannel]
  17. type
  18. MyObject[T] = object
  19. x: T
  20. var global: MyObject[string]
  21. var globalB: MyObject[float]
  22. proc consumer(ix : int) {.thread.} =
  23. echo channels[ix].recv() ###### not GC-safe: 'channels'
  24. echo globalB
  25. proc main =
  26. for ix in 1..3: channels[ix].open()
  27. for ix in 1..3: spawn consumer(ix)
  28. for ix in 1..3: channels[ix].send("test")
  29. sync()
  30. for ix in 1..3: channels[ix].close()
  31. when true:
  32. main()