mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-29 19:30:36 +02:00
Revert "futures: Limit the number of nested futures on the same stack."
This reverts commit 8a177d316c
, though
keeping the additional tests. (Guile 2.2 doesn't have a fixed stack
limit).
This commit is contained in:
parent
70d4c4b284
commit
9e28a12121
2 changed files with 7 additions and 23 deletions
|
@ -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
|
||||
@code{(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:
|
||||
|
||||
|
|
|
@ -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)))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue