diff options
Diffstat (limited to 'tests/parallel')
-rw-r--r-- | tests/parallel/tarray_of_channels.nim | 26 | ||||
-rw-r--r-- | tests/parallel/tdont_be_stupid.nim | 15 | ||||
-rw-r--r-- | tests/parallel/tgc_unsafe.nim | 32 |
3 files changed, 73 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/tdont_be_stupid.nim b/tests/parallel/tdont_be_stupid.nim new file mode 100644 index 000000000..a7e82466a --- /dev/null +++ b/tests/parallel/tdont_be_stupid.nim @@ -0,0 +1,15 @@ + +import threadpool, os + +proc single(time: int) = + sleep time + echo time + +proc sleepsort(nums: openArray[int]) = + parallel: + var i = 0 + while i <= len(nums) + -1: + spawn single(nums[i]) + i += 1 + +sleepsort([50,3,40,25]) 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() |