[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/07: workers: 'pool-idle?' returns true only if the workers are idle.
From: |
Ludovic Courtès |
Subject: |
01/07: workers: 'pool-idle?' returns true only if the workers are idle. |
Date: |
Fri, 17 Nov 2017 05:09:42 -0500 (EST) |
civodul pushed a commit to branch master
in repository guix.
commit 232b3d31016439b5600e47d845ffb7c9a4ee4723
Author: Ludovic Courtès <address@hidden>
Date: Fri Nov 17 10:10:30 2017 +0100
workers: 'pool-idle?' returns true only if the workers are idle.
Fixes <https://bugs.gnu.org/28779>.
Reported by Eric Bavier <address@hidden>.
* guix/workers.scm (<pool>)[busy]: New field.
(worker-thunk): Add #:idle and #:busy and use them.
(make-pool): Pass #:busy and #:idle to 'worker-thunk'. Pass a 'busy'
value to '%make-pool'.
* guix/workers.scm (pool-idle?): Check whether 'pool-busy' returns zero
and adjust docstring.
---
guix/workers.scm | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/guix/workers.scm b/guix/workers.scm
index 846f5e5..0f6f54b 100644
--- a/guix/workers.scm
+++ b/guix/workers.scm
@@ -45,12 +45,13 @@
;;; Code:
(define-record-type <pool>
- (%make-pool queue mutex condvar workers)
+ (%make-pool queue mutex condvar workers busy)
pool?
(queue pool-queue)
(mutex pool-mutex)
(condvar pool-condition-variable)
- (workers pool-workers))
+ (workers pool-workers)
+ (busy pool-busy))
(define-syntax-rule (without-mutex mutex exp ...)
(dynamic-wind
@@ -62,12 +63,14 @@
(lock-mutex mutex))))
(define* (worker-thunk mutex condvar pop-queue
- #:key (thread-name "guix worker"))
+ #:key idle busy (thread-name "guix worker"))
"Return the thunk executed by worker threads."
(define (loop)
(match (pop-queue)
(#f ;empty queue
- (wait-condition-variable condvar mutex))
+ (idle)
+ (wait-condition-variable condvar mutex)
+ (busy))
((? procedure? proc)
;; Release MUTEX while executing PROC.
(without-mutex mutex
@@ -97,19 +100,24 @@ threads as reported by the operating system."
(let* ((mutex (make-mutex))
(condvar (make-condition-variable))
(queue (make-q))
+ (busy count)
(procs (unfold (cut >= <> count)
(lambda (n)
(worker-thunk mutex condvar
(lambda ()
(and (not (q-empty? queue))
(q-pop! queue)))
+ #:busy (lambda ()
+ (set! busy (+ 1 busy)))
+ #:idle (lambda ()
+ (set! busy (- busy 1)))
#:thread-name thread-name))
1+
0))
(threads (map (lambda (proc)
(call-with-new-thread proc))
procs)))
- (%make-pool queue mutex condvar threads)))
+ (%make-pool queue mutex condvar threads (lambda () busy))))
(define (pool-enqueue! pool thunk)
"Enqueue THUNK for future execution by POOL."
@@ -118,9 +126,11 @@ threads as reported by the operating system."
(signal-condition-variable (pool-condition-variable pool))))
(define (pool-idle? pool)
- "Return true if POOL doesn't have any task in its queue."
+ "Return true if POOL doesn't have any task in its queue and all the workers
+are currently idle (i.e., waiting for a task)."
(with-mutex (pool-mutex pool)
- (q-empty? (pool-queue pool))))
+ (and (q-empty? (pool-queue pool))
+ (zero? ((pool-busy pool))))))
(define-syntax-rule (eventually pool exp ...)
"Run EXP eventually on one of the workers of POOL."
- branch master updated (ef2c6b4 -> 9bc646d), Ludovic Courtès, 2017/11/17
- 01/07: workers: 'pool-idle?' returns true only if the workers are idle.,
Ludovic Courtès <=
- 03/07: workers: Display backtrace in pre-unwind handler., Ludovic Courtès, 2017/11/17
- 02/07: workers: Add test with exceptions., Ludovic Courtès, 2017/11/17
- 06/07: gnu: gnome-disk-utility: Update to 3.26.2., Ludovic Courtès, 2017/11/17
- 04/07: gnu: libnftnl: Update to 1.0.8., Ludovic Courtès, 2017/11/17
- 07/07: gnu: eog: Update to 3.26.2., Ludovic Courtès, 2017/11/17
- 05/07: gnu: nftables: Update to 0.8., Ludovic Courtès, 2017/11/17