diff options
author | Araq <rumpf_a@web.de> | 2015-03-16 22:39:48 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-03-16 23:02:20 +0100 |
commit | bc264618f532013e8816a824fb41a6b1cfbee712 (patch) | |
tree | 00eeaac0bbc195c9eb69232b1d81a2e5f0b1f69b /tests/parallel | |
parent | f9a3de984d17f2a9a7fc056d3f35b2c9987952d3 (diff) | |
download | Nim-bc264618f532013e8816a824fb41a6b1cfbee712.tar.gz |
fixes #2257
Diffstat (limited to 'tests/parallel')
-rw-r--r-- | tests/parallel/tarray_of_channels.nim | 26 | ||||
-rw-r--r-- | tests/parallel/tgc_unsafe.nim | 32 |
2 files changed, 58 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..11b523401 --- /dev/null +++ b/tests/parallel/tarray_of_channels.nim @@ -0,0 +1,26 @@ +# bug #2257 +import threadpool + +type StringChannel = TChannel[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 isMainModule: + main() diff --git a/tests/parallel/tgc_unsafe.nim b/tests/parallel/tgc_unsafe.nim new file mode 100644 index 000000000..6548bbec8 --- /dev/null +++ b/tests/parallel/tgc_unsafe.nim @@ -0,0 +1,32 @@ +discard """ + errormsg: "'consumer' is not GC-safe" + line: 19 +""" + +# bug #2257 +import threadpool + +type StringChannel = TChannel[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 global + 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 isMainModule: + main() |