diff options
author | cooldome <cdome@bk.ru> | 2020-04-16 22:27:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 23:27:08 +0200 |
commit | d3b0132061235f316ac554690eb7e471caf95955 (patch) | |
tree | 0c97534f32b2b8cb01af355071bf6ed6ba4d6daf /tests/arc | |
parent | 9295251e68ee86b512de51a2f650729ac6893104 (diff) | |
download | Nim-d3b0132061235f316ac554690eb7e471caf95955.tar.gz |
Step2: fixes #13781, fixes #13805 (#13897)
* Fix sym owner in wrapper proc * threadpool changes * revert lowerings * add newFastMoveStmt * try fixing test by switching to cpp Co-authored-by: cooldome <ariabushenko@bk.ru>
Diffstat (limited to 'tests/arc')
-rw-r--r-- | tests/arc/tthread.nim | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/arc/tthread.nim b/tests/arc/tthread.nim new file mode 100644 index 000000000..c653c753f --- /dev/null +++ b/tests/arc/tthread.nim @@ -0,0 +1,63 @@ +discard """ + cmd: "nim cpp --gc:arc --threads:on $file" + output: '''ok1 +ok2 +destroyed +destroyed +destroyed +''' +""" +import threadpool, os + +type + MyObj = object + p: int + MyObjRef = ref MyObj + +proc `=destroy`(x: var MyObj) = + if x.p != 0: + echo "destroyed" + +proc thread1(): string = + os.sleep(1000) + return "ok1" + +proc thread2(): ref string = + os.sleep(1000) + new(result) + result[] = "ok2" + +proc thread3(): ref MyObj = + os.sleep(1000) + new(result) + result[].p = 2 + +var fv1 = spawn thread1() +var fv2 = spawn thread2() +var fv3 = spawn thread3() +sync() +echo ^fv1 +echo (^fv2)[] + + +proc thread4(x: MyObjRef): MyObjRef {.nosinks.} = + os.sleep(1000) + result = x + +proc thread5(x: sink MyObjRef): MyObjRef = + os.sleep(1000) + result = x + +proc ref_forwarding_test = + var x = new(MyObj) + x[].p = 2 + var y = spawn thread4(x) + +proc ref_sink_forwarding_test = + var x = new(MyObj) + x[].p = 2 + var y = spawn thread5(x) + +ref_forwarding_test() +ref_sink_forwarding_test() +sync() |