summary refs log tree commit diff stats
path: root/tests/parallel/tarray_of_channels.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parallel/tarray_of_channels.nim')
-rw-r--r--tests/parallel/tarray_of_channels.nim39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/parallel/tarray_of_channels.nim b/tests/parallel/tarray_of_channels.nim
new file mode 100644
index 000000000..9479227aa
--- /dev/null
+++ b/tests/parallel/tarray_of_channels.nim
@@ -0,0 +1,39 @@
+discard """
+sortoutput: true
+output: '''
+(x: 0.0)
+(x: 0.0)
+(x: 0.0)
+test
+test
+test
+'''
+disabled: "openbsd"
+"""
+
+# bug #2257
+import threadpool
+
+type StringChannel = Channel[string]
+var channels: array[1..3, StringChannel]
+
+type
+  MyObject[T] = object
+    x: T
+
+var global: MyObject[string]
+var globalB: MyObject[float]
+
+proc consumer(ix : int) {.thread.} =
+  echo channels[ix].recv() ###### not GC-safe: 'channels'
+  echo globalB
+
+proc main =
+  for ix in 1..3: channels[ix].open()
+  for ix in 1..3: spawn consumer(ix)
+  for ix in 1..3: channels[ix].send("test")
+  sync()
+  for ix in 1..3: channels[ix].close()
+
+when true:
+  main()