Test case for #5626 (#8204)

This commit is contained in:
genotrance
2018-07-03 21:47:50 -05:00
committed by Varriount
parent ab47a870bc
commit c7cc934632

27
tests/threads/t5626.nim Normal file
View File

@@ -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)