mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-02 03:54:44 +00:00
fixes #2257
This commit is contained in:
26
tests/parallel/tarray_of_channels.nim
Normal file
26
tests/parallel/tarray_of_channels.nim
Normal file
@@ -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()
|
||||
32
tests/parallel/tgc_unsafe.nim
Normal file
32
tests/parallel/tgc_unsafe.nim
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user