diff --git a/gc.c b/gc.c index 7fd166f9..075a11e9 100644 --- a/gc.c +++ b/gc.c @@ -1044,9 +1044,9 @@ void gc_mut_cooperate(gc_thread_data * thd, int buf_len) gc_mark_gray(thd, thd->gc_args[i]); } // Mark thread object, if applicable. Very likely this is its only ref -// if (thd->scm_thread_obj) { -// gc_mark_gray(thd, thd->scm_thread_obj); -// } + if (thd->scm_thread_obj) { + gc_mark_gray(thd, thd->scm_thread_obj); + } // Also, mark everything the collector moved to the heap for (i = 0; i < buf_len; i++) { gc_mark_gray(thd, thd->moveBuf[i]); diff --git a/srfi/18.sld b/srfi/18.sld index 7aaafc2c..845a3a1e 100644 --- a/srfi/18.sld +++ b/srfi/18.sld @@ -18,7 +18,7 @@ thread-sleep! thread-yield! thread-terminate! - ;; TODO: current-thread + current-thread ;; TODO: thread-join! mutex? @@ -72,8 +72,19 @@ (define (thread-specific t) (vector-ref t 4)) (define (thread-specific-set! t obj) (vector-set! t 4 obj)) - ; TODO: - ; current-thread - not sure how to look this up yet... may need a global list of running threads. Unfortunately need the vector here + (define (current-thread) + (let ((t (%current-thread))) + (if (null? t) + *primordial-thread* + t))) + + (define *primordial-thread* + (vector 'cyc-thread-obj #f #f "main thread" #f)) + + (define-c %current-thread + "(void *data, int argc, closure _, object k)" + " gc_thread_data *td = (gc_thread_data *)data; + return_closcall1(data, k, td->scm_thread_obj); ") (define (thread-start! t) ;; Initiate a GC prior to running the thread, in case @@ -83,6 +94,7 @@ (Cyc-minor-gc) (let ((mutator-id (Cyc-spawn-thread! thread-params))) (vector-set! t 2 mutator-id)))) + (define (thread-yield!) (thread-sleep! 1)) (define-c thread-terminate! "(void *data, int argc, closure _, object k)"