summary refs log tree commit diff stats
path: root/lib/pure/concurrency
diff options
context:
space:
mode:
authorȘtefan Talpalaru <stefantalpalaru@yahoo.com>2019-05-15 08:42:30 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-05-15 08:42:30 +0200
commitdfc768542017d1a89dfefe65cfe9fd4da4ab1ed5 (patch)
treed6ee6291c689a22cfe9b885211dff1372d8f7e62 /lib/pure/concurrency
parentbc0f2f0dd2128805c82ea8bc96b5d757ef1e92f8 (diff)
downloadNim-dfc768542017d1a89dfefe65cfe9fd4da4ab1ed5.tar.gz
fixes #11250 (#11251)
Diffstat (limited to 'lib/pure/concurrency')
-rw-r--r--lib/pure/concurrency/threadpool.nim12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/pure/concurrency/threadpool.nim b/lib/pure/concurrency/threadpool.nim
index 15dbb10de..04be704be 100644
--- a/lib/pure/concurrency/threadpool.nim
+++ b/lib/pure/concurrency/threadpool.nim
@@ -18,7 +18,7 @@
 when not compileOption("threads"):
   {.error: "Threadpool requires --threads:on option.".}
 
-import cpuinfo, cpuload, locks
+import cpuinfo, cpuload, locks, os
 
 {.push stackTrace:off.}
 
@@ -570,17 +570,15 @@ proc sync*() =
   ## A simple barrier to wait for all ``spawn``'ed tasks.
   ##
   ## If you need more elaborate waiting, you have to use an explicit barrier.
-  var toRelease = 0
   while true:
     var allReady = true
     for i in 0 ..< currentPoolSize:
       if not allReady: break
       allReady = allReady and workersData[i].ready
     if allReady: break
-    blockUntil(gSomeReady)
-    inc toRelease
-
-  for i in 0 ..< toRelease:
-    signal(gSomeReady)
+    sleep(100)
+    # 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
+    # "signal(gSomeReady)" from inside "slave()" that can never come.
 
 setup()