mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +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,
|
calling future's continuation, and later reinstating it (@pxref{Prompts,
|
||||||
delimited continuations}).
|
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
|
@deffn {Scheme Syntax} future exp
|
||||||
Return a future for expression @var{exp}. This is equivalent to:
|
Return a future for expression @var{exp}. This is equivalent to:
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
;;; -*- mode: scheme; coding: utf-8; -*-
|
;;; -*- 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
|
;;; This library is free software; you can redistribute it and/or
|
||||||
;;; modify it under the terms of the GNU Lesser General Public
|
;;; 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.
|
;; A mapping of nested futures to futures waiting for them to complete.
|
||||||
(define %futures-waiting '())
|
(define %futures-waiting '())
|
||||||
|
|
||||||
;; Nesting level of futures. Incremented each time a future is touched
|
;; Whether currently running within a future.
|
||||||
;; from within a future.
|
(define %within-future? (make-parameter #f))
|
||||||
(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)
|
|
||||||
|
|
||||||
(define-syntax-rule (with-mutex m e0 e1 ...)
|
(define-syntax-rule (with-mutex m e0 e1 ...)
|
||||||
;; Copied from (ice-9 threads) to avoid circular dependency.
|
;; Copied from (ice-9 threads) to avoid circular dependency.
|
||||||
|
@ -153,8 +147,7 @@ adding it to the waiter queue."
|
||||||
(thunk (lambda ()
|
(thunk (lambda ()
|
||||||
(call-with-prompt %future-prompt
|
(call-with-prompt %future-prompt
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(parameterize ((%nesting-level
|
(parameterize ((%within-future? #t))
|
||||||
(1+ (%nesting-level))))
|
|
||||||
((future-thunk future))))
|
((future-thunk future))))
|
||||||
suspend))))
|
suspend))))
|
||||||
(set-future-result! future
|
(set-future-result! future
|
||||||
|
@ -253,16 +246,14 @@ adding it to the waiter queue."
|
||||||
(unlock-mutex (future-mutex future)))
|
(unlock-mutex (future-mutex future)))
|
||||||
((started)
|
((started)
|
||||||
(unlock-mutex (future-mutex future))
|
(unlock-mutex (future-mutex future))
|
||||||
(if (> (%nesting-level) 0)
|
(if (%within-future?)
|
||||||
(abort-to-prompt %future-prompt future)
|
(abort-to-prompt %future-prompt future)
|
||||||
(begin
|
(begin
|
||||||
(work)
|
(work)
|
||||||
(loop))))
|
(loop))))
|
||||||
(else ; queued
|
(else
|
||||||
(unlock-mutex (future-mutex future))
|
(unlock-mutex (future-mutex future))
|
||||||
(if (> (%nesting-level) %max-nesting-level)
|
(work)
|
||||||
(abort-to-prompt %future-prompt future)
|
|
||||||
(work))
|
|
||||||
(loop))))
|
(loop))))
|
||||||
((future-result future)))
|
((future-result future)))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue