From bf9dda2fed2d700e61df8061726628b3a5e52389 Mon Sep 17 00:00:00 2001 From: Yorick Hardy Date: Fri, 15 Nov 2024 23:11:21 +0200 Subject: [PATCH] srfi-18: call Cyc_end_thread on thread exits This ensures that the collector has a chance to run whenever a thread exits. Attempts to partially address issue #534. --- srfi/18.sld | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/srfi/18.sld b/srfi/18.sld index afe13b84..fbc22c8f 100644 --- a/srfi/18.sld +++ b/srfi/18.sld @@ -118,13 +118,21 @@ make_c_opaque(co, td); return_closcall1(data, k, &co); ") + (define-c %end-thread! + "(void *data, int argc, closure _, object k, object ret)" + " gc_thread_data *d = data; + vector_type *v = d->scm_thread_obj; + v->elements[7] = ret; // Store thread result + Cyc_end_thread(d); + return_closcall1(data, k, boolean_f);") + (define (thread-start! t) ;; Initiate a GC prior to running the thread, in case ;; it contains any closures on the "parent" thread's stack (let* ((thunk (vector-ref t 1)) (thread-params (cons t (lambda () (vector-set! t 5 #f) - (thunk))))) + (let ((r (thunk))) (%end-thread! r)))))) (vector-set! t 5 (%get-thread-data)) ;; Temporarily make parent thread ;; data available for child init (Cyc-minor-gc)