[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/01: Revert "futures: Limit the number of nested futur
From: |
Andy Wingo |
Subject: |
[Guile-commits] 01/01: Revert "futures: Limit the number of nested futures on the same stack." |
Date: |
Tue, 28 Feb 2017 04:53:52 -0500 (EST) |
wingo pushed a commit to branch master
in repository guile.
commit 9e28a12121414b4b0508d56c9fe011d9059f48b7
Author: Andy Wingo <address@hidden>
Date: Tue Feb 28 10:45:21 2017 +0100
Revert "futures: Limit the number of nested futures on the same stack."
This reverts commit 8a177d316c0062afe74f9a761ef460e297435e59, though
keeping the additional tests. (Guile 2.2 doesn't have a fixed stack
limit).
---
doc/ref/api-scheduling.texi | 7 -------
module/ice-9/futures.scm | 23 +++++++----------------
2 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/doc/ref/api-scheduling.texi b/doc/ref/api-scheduling.texi
index bf85a64..ff8473a 100644
--- a/doc/ref/api-scheduling.texi
+++ b/doc/ref/api-scheduling.texi
@@ -830,13 +830,6 @@ future has completed. This suspend/resume is achieved by
capturing the
calling future's continuation, and later reinstating it (@pxref{Prompts,
delimited continuations}).
-Note that @code{par-map} above is not tail-recursive. This could lead
-to stack overflows when @var{lst} is large compared to
address@hidden(current-processor-count)}. To address that, @code{touch} uses
-the suspend mechanism described above to limit the number of nested
-futures executing on the same stack. Thus, the above code should never
-run into stack overflows.
-
@deffn {Scheme Syntax} future exp
Return a future for expression @var{exp}. This is equivalent to:
diff --git a/module/ice-9/futures.scm b/module/ice-9/futures.scm
index cc57e5c..4a46283 100644
--- a/module/ice-9/futures.scm
+++ b/module/ice-9/futures.scm
@@ -1,6 +1,6 @@
;;; -*- mode: scheme; coding: utf-8; -*-
;;;
-;;; Copyright (C) 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+;;; Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
@@ -90,14 +90,8 @@ touched."
;; A mapping of nested futures to futures waiting for them to complete.
(define %futures-waiting '())
-;; Nesting level of futures. Incremented each time a future is touched
-;; from within a future.
-(define %nesting-level (make-parameter 0))
-
-;; Maximum nesting level. The point is to avoid stack overflows when
-;; nested futures are executed on the same stack. See
-;; <http://bugs.gnu.org/13188>.
-(define %max-nesting-level 200)
+;; Whether currently running within a future.
+(define %within-future? (make-parameter #f))
(define-syntax-rule (with-mutex m e0 e1 ...)
;; Copied from (ice-9 threads) to avoid circular dependency.
@@ -153,8 +147,7 @@ adding it to the waiter queue."
(thunk (lambda ()
(call-with-prompt %future-prompt
(lambda ()
- (parameterize ((%nesting-level
- (1+ (%nesting-level))))
+ (parameterize ((%within-future? #t))
((future-thunk future))))
suspend))))
(set-future-result! future
@@ -253,16 +246,14 @@ adding it to the waiter queue."
(unlock-mutex (future-mutex future)))
((started)
(unlock-mutex (future-mutex future))
- (if (> (%nesting-level) 0)
+ (if (%within-future?)
(abort-to-prompt %future-prompt future)
(begin
(work)
(loop))))
- (else ; queued
+ (else
(unlock-mutex (future-mutex future))
- (if (> (%nesting-level) %max-nesting-level)
- (abort-to-prompt %future-prompt future)
- (work))
+ (work)
(loop))))
((future-result future)))