srfi-18: thread-terminate! takes a thread as argument

This commit is contained in:
Yorick Hardy 2024-11-17 23:07:42 +02:00
parent 20fc3c6646
commit 41ac00d6be

View file

@ -140,9 +140,19 @@
t)) t))
(define (thread-yield!) (thread-sleep! 1)) (define (thread-yield!) (thread-sleep! 1))
(define-c thread-terminate!
"(void *data, object _, int argc, object *args)" (define-c %thread-terminate!
" Cyc_end_thread(data); ") "(void *data, int argc, closure _, object k, object thread_data_opaque)"
" gc_thread_data *td = (gc_thread_data *)(opaque_ptr(thread_data_opaque));
Cyc_end_thread(td);
/* TODO: if terminating the current thread, don't return */
return_closcall1(data, k, boolean_t);")
(define (thread-terminate! t)
(cond
((and (thread? t) (Cyc-opaque? (vector-ref t 2)))
(%thread-terminate! (vector-ref t 2)))
(else
#f))) ;; TODO: raise an error instead?
;; TODO: not good enough, need to return value from thread ;; TODO: not good enough, need to return value from thread
;; TODO: perhaps not an ideal solution using a loop/polling below, but good ;; TODO: perhaps not an ideal solution using a loop/polling below, but good