diff options
author | Araq <rumpf_a@web.de> | 2015-04-19 13:36:22 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-04-19 13:36:22 +0200 |
commit | 89cbf092b23b901cd6a485ab670b1e374c31559d (patch) | |
tree | 8cc54972f4d191abde31daef6e7917536fad6180 /tests | |
parent | 5cea6807e1b0b8bf2c12d3178ba782c2eaa03610 (diff) | |
download | Nim-89cbf092b23b901cd6a485ab670b1e374c31559d.tar.gz |
fixes a serious codegen bug that caused to emit wrong barriers in rare cases
Diffstat (limited to 'tests')
-rw-r--r-- | tests/parallel/twrong_refcounts.nim | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/parallel/twrong_refcounts.nim b/tests/parallel/twrong_refcounts.nim new file mode 100644 index 000000000..db32a96d8 --- /dev/null +++ b/tests/parallel/twrong_refcounts.nim @@ -0,0 +1,53 @@ +discard """ + output: "Success" +""" + +import math, threadPool + +# --- + +type + Person = object + age: int + friend: ref Person + +var + people: seq[ref Person] = @[] + +proc newPerson(age:int): ref Person = + result.new() + result.age = age + +proc greet(p:Person) = + #echo p.age, ", ", p.friend.age + p.friend.age += 1 + +# --- + +proc setup = + for i in 0 .. <20: + people.add newPerson(i + 1) + for i in 0 .. <20: + people[i].friend = people[random(20)] + +proc update = + var countA: array[20, int] + var countB: array[20, int] + + for i, p in people: + countA[i] = getRefCount(p) + parallel: + for i in 0 .. people.high: + spawn greet(people[i][]) + for i, p in people: + countB[i] = getRefCount(p) + + for i in 0 .. <20: + doAssert countA[i] == countB[i] + echo "Success" + +# --- + +when isMainModule: + setup() + update() |