unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Futures: Avoid creating the worker pool more than once
@ 2012-11-06 23:07 Mark H Weaver
  2012-11-07 13:46 ` Mark H Weaver
  2012-11-08 19:11 ` Ludovic Courtès
  0 siblings, 2 replies; 9+ messages in thread
From: Mark H Weaver @ 2012-11-06 23:07 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 49 bytes --]

Any objections to applying this fix?

     Mark


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: [PATCH] Futures: Avoid creating the worker pool more than once --]
[-- Type: text/x-diff, Size: 1661 bytes --]

From ff2c84b118b68020805eae93f71c3a8fd13ca3d9 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Tue, 6 Nov 2012 18:03:39 -0500
Subject: [PATCH] Futures: Avoid creating the worker pool more than once.

* module/ice-9/futures.scm (%create-workers!): Check to make sure the
  worker pool hasn't already been created within the critical section.
---
 module/ice-9/futures.scm |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/module/ice-9/futures.scm b/module/ice-9/futures.scm
index 0f64b5c..afdf48f 100644
--- a/module/ice-9/futures.scm
+++ b/module/ice-9/futures.scm
@@ -158,13 +158,19 @@ touched."
 
 (define (%create-workers!)
   (lock-mutex %futures-mutex)
-  (set! %workers
-        (unfold (lambda (i) (>= i %worker-count))
-                (lambda (i)
-                  (call-with-new-thread process-futures))
-                1+
-                0))
-  (set! create-workers! (lambda () #t))
+  ;; setting 'create-workers!' to a no-op is an optimization, but it is
+  ;; still possible for '%create-workers!' to be called more than once
+  ;; from different threads.  Therefore, to avoid creating %workers more
+  ;; than once (and thus creating too many threads), we check to make
+  ;; sure %workers is empty within the critical section.
+  (when (null? %workers)
+    (set! create-workers! (lambda () #t))
+    (set! %workers
+          (unfold (lambda (i) (>= i %worker-count))
+                  (lambda (i)
+                    (call-with-new-thread process-futures))
+                  1+
+                  0)))
   (unlock-mutex %futures-mutex))
 
 (define create-workers!
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-11-30 20:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-06 23:07 [PATCH] Futures: Avoid creating the worker pool more than once Mark H Weaver
2012-11-07 13:46 ` Mark H Weaver
2012-11-07 14:14   ` Daniel Hartwig
2012-11-16 23:15   ` Ludovic Courtès
2012-11-30 19:01     ` Mark H Weaver
2012-11-30 20:14       ` Ludovic Courtès
2012-11-08 19:11 ` Ludovic Courtès
2012-11-10  3:13   ` Mark H Weaver
2012-11-10 13:53     ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).