This commit is contained in:
Ștefan Talpalaru 2019-05-15 08:42:30 +02:00 • committed by Andreas Rumpf
commit dfc7685420

View file

@ -18,7 +18,7 @@
when not compileOption("threads"): when not compileOption("threads"):
{.error: "Threadpool requires --threads:on option.".} {.error: "Threadpool requires --threads:on option.".}
import cpuinfo, cpuload, locks import cpuinfo, cpuload, locks, os
{.push stackTrace:off.} {.push stackTrace:off.}
@ -570,17 +570,15 @@ proc sync*() =
## A simple barrier to wait for all ``spawn``'ed tasks. ## A simple barrier to wait for all ``spawn``'ed tasks.
## ##
## If you need more elaborate waiting, you have to use an explicit barrier. ## If you need more elaborate waiting, you have to use an explicit barrier.
var toRelease = 0
while true: while true:
var allReady = true var allReady = true
for i in 0 ..< currentPoolSize: for i in 0 ..< currentPoolSize:
if not allReady: break if not allReady: break
allReady = allReady and workersData[i].ready allReady = allReady and workersData[i].ready
if allReady: break if allReady: break
blockUntil(gSomeReady) sleep(100)
inc toRelease # We cannot "blockUntil(gSomeReady)" because workers may be shut down between
# the time we establish that some are not "ready" and the time we wait for a
for i in 0 ..< toRelease: # "signal(gSomeReady)" from inside "slave()" that can never come.
signal(gSomeReady)
setup() setup()