mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-19 05:39:17 +02:00
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.
This commit is contained in:
parent
955695f554
commit
bf9dda2fed
1 changed files with 9 additions and 1 deletions
10
srfi/18.sld
10
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue