From c7cc93463233cba085db1f36746355848a27ae4d Mon Sep 17 00:00:00 2001 From: genotrance Date: Tue, 3 Jul 2018 21:47:50 -0500 Subject: [PATCH] Test case for #5626 (#8204) --- tests/threads/t5626.nim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/threads/t5626.nim diff --git a/tests/threads/t5626.nim b/tests/threads/t5626.nim new file mode 100644 index 0000000000000..e7024e5ed10cf --- /dev/null +++ b/tests/threads/t5626.nim @@ -0,0 +1,27 @@ +import threadpool + +var ch: Channel[int] +ch.open +var pch = ch.addr + +proc run(f: proc(): int {.gcsafe.}): proc() = + let r = spawn f() + return proc() = await(r) + +var working = false + +proc handler(): int = + while true: + let (h, v) = pch[].tryRecv() + if not h: + discard cas(working.addr, true, false) + break + 1 + +proc send(x: int) = + ch.send(x) + if cas(working.addr, false, true): + discard run(handler) + +for x in 0..1000000: + send(x) \ No newline at end of file