1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

futures: Have workers work when futures are available.

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.
This commit is contained in:
Ludovic Courtès 2012-11-03 01:05:19 +01:00
parent 1d4e6ee301
commit 134c95f1e6

View 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))