Skip to content

Commit

Permalink
Test case for #5626 (#8204)
Browse files Browse the repository at this point in the history
  • Loading branch information
genotrance authored and Varriount committed Jul 4, 2018
1 parent ab47a87 commit c7cc934
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/threads/t5626.nim
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c7cc934

Please sign in to comment.