From 8a177d316c0062afe74f9a761ef460e297435e59 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 27 Mar 2013 18:03:47 +0100 Subject: futures: Limit the number of nested futures on the same stack. Fixes . Reported by Nala Ginrut . * module/ice-9/futures.scm (%nesting-level): Rename to... (%nesting-level): ... this. Default to 0 instead of #f. Update users. (%max-nesting-level): New variable. (touch): When FUTURE is queued and (%nesting-level) is above %MAX-NESTING-LEVEL, abort to %FUTURE-PROMPT. * test-suite/tests/future.test ("nested futures")["loop"]: Remove `compile' call. * test-suite/tests/threads.test ("par-map")["long list"]: New test. * doc/ref/api-scheduling.texi (Futures): Add a paragraph about stack consumption. --- doc/ref/api-scheduling.texi | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'doc/ref/api-scheduling.texi') diff --git a/doc/ref/api-scheduling.texi b/doc/ref/api-scheduling.texi index e040904cf..b23082192 100644 --- a/doc/ref/api-scheduling.texi +++ b/doc/ref/api-scheduling.texi @@ -1037,6 +1037,13 @@ 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: -- cgit v1.2.3