futures: Have workers work when futures are available.
authorLudovic Courtès <ludo@gnu.org>
Sat, 3 Nov 2012 00:05:19 +0000 (01:05 +0100)
committerLudovic Courtès <ludo@gnu.org>
Sat, 3 Nov 2012 00:05:19 +0000 (01:05 +0100)
Reported by David Pirotte.

* module/ice-9/futures.scm (process-futures): Wait on %FUTURES-AVAILABLE
  only when %FUTURES is empty.

  The problem was obvious when running (begin (use-modules (ice-9
  threads)) (par-map 1+ (iota 400000))) : eventually, only the main
  thread would do the work, while the others would remain idle, waiting
  on %FUTURES-AVAILABLE.

module/ice-9/futures.scm

index 3c4cd7d..2ab3edd 100644 (file)
@@ -93,8 +93,10 @@ touched."
   ;; Wait for futures to be available and process them.
   (lock-mutex %futures-mutex)
   (let loop ()
-    (wait-condition-variable %futures-available
-                             %futures-mutex)
+    (when (q-empty? %futures)
+      (wait-condition-variable %futures-available
+                               %futures-mutex))
+
     (or (q-empty? %futures)
         (let ((future (deq! %futures)))
           (lock-mutex (future-mutex future))