mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 02:12:11 +00:00
This reverts commit c7cc934632.
This commit is contained in:
committed by
Andreas Rumpf
parent
c7cc934632
commit
f7b76c9ea7
@@ -1,27 +0,0 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user