diff options
author | Araq <rumpf_a@web.de> | 2015-04-04 00:22:42 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-04-04 01:19:32 +0200 |
commit | a83286192ff286ce01f2223e16b1135a996c9f6c (patch) | |
tree | 8ea411839d4037630c7cbf15e53e64e0c762af8d /tests/parallel | |
parent | f767e1749e19eb22f0e4ddb128e5d1925b8eb443 (diff) | |
download | Nim-a83286192ff286ce01f2223e16b1135a996c9f6c.tar.gz |
GC-safety error messages are useful now
Diffstat (limited to 'tests/parallel')
-rw-r--r-- | tests/parallel/tgc_unsafe2.nim | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/parallel/tgc_unsafe2.nim b/tests/parallel/tgc_unsafe2.nim new file mode 100644 index 000000000..ec4605fe9 --- /dev/null +++ b/tests/parallel/tgc_unsafe2.nim @@ -0,0 +1,39 @@ +discard """ + line: 28 + nimout: '''tgc_unsafe2.nim(22, 5) Warning: 'trick' is not GC-safe as it accesses 'global' which is a global using GC'ed memory +tgc_unsafe2.nim(26, 5) Warning: 'track' is not GC-safe as it calls 'trick' +tgc_unsafe2.nim(28, 5) Error: 'consumer' is not GC-safe as it calls 'track' +''' + errormsg: "'consumer' is not GC-safe as it calls 'track'" +""" + +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 trick(ix: int) = + echo global.x + echo channels[ix].recv() + +proc track(ix: int) = trick(ix) + +proc consumer(ix: int) {.thread.} = + track(ix) + +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() |