~ chicken-core (master) 596332d69e47a5d04fe5e4f5f609c3e4ab8fcdba
commit 596332d69e47a5d04fe5e4f5f609c3e4ab8fcdba
Author: Peter Bex <peter@more-magic.net>
AuthorDate: Tue Oct 10 17:29:44 2017 +0200
Commit: Kooda <kooda@upyum.com>
CommitDate: Sun Oct 22 13:38:48 2017 +0200
Threads are tricky business. We must sacrifice a goat in the name of the dark gods to make them work properly!
When scheduling a new thread, we need to invoke it with a continuation
that goes nowhere. We know the thread call won't return, so the
continuation must be swapped out because the scheduler continuation
still has a reference to the old thread before invocation. This
continuation itself still may holds a reference to the previous
thread, and so on, resulting in infinite memory buildup.
This fixes #1367
Signed-off-by: Kooda <kooda@upyum.com>
diff --git a/NEWS b/NEWS
index acce52f6..c14fea47 100644
--- a/NEWS
+++ b/NEWS
@@ -136,6 +136,9 @@
- Runtime system:
- The profiler no longer uses malloc from a signal handler which may
cause deadlocks (#1414, thanks to Lemonboy).
+ - The scheduler no longer indirectly hangs on to the old thread
+ when switching to a new one, which caused excessive memory
+ consumption (#1367, thanks to "megane").
- Syntax expander
- Renaming an identifier twice no longer results in an undo of the
diff --git a/scheduler.scm b/scheduler.scm
index 72b8ad06..a6440001 100644
--- a/scheduler.scm
+++ b/scheduler.scm
@@ -170,7 +170,9 @@ EOF
(##sys#restore-thread-state-buffer thread)
;;XXX WRONG! this sets the t/i-period ("quantum") for the _next_ thread
(##core#inline "C_set_initial_timer_interrupt_period" (##sys#slot thread 9))
- ((##sys#slot thread 1)) )
+ ;; Call upon ye ancient gods to forget about the current
+ ;; continuation; it still refers to the old thread (#1367).
+ (##sys#call-with-cthulhu (##sys#slot thread 1)) )
(let* ([ct ##sys#current-thread]
[eintr #f]
[cts (##sys#slot ct 3)] )
Trap