Re: Quick question on thread-interrupt!
Marc Feeley 07 Nov 2022 20:35 UTC
> On Nov 7, 2022, at 1:19 PM, Marc Feeley <xxxxxx@iro.umontreal.ca> wrote:
>
> Note that ##thread-call can be written on top of ##thread-int! (using a mutex to wait for the result). So ##thread-int! is the fundamental primitive.
For completeness here is the implementation:
(define (make-locked-mutex)
(let ((mut (make-mutex)))
(mutex-lock! mut)
mut))
(define (thread-call thread thunk)
(let ((mut (make-locked-mutex))
(result #f))
(##thread-int!
thread
(lambda ()
(set! result (thunk))
(mutex-unlock! mut))) ;; result is ready!
(mutex-lock! mut) ;; wait for result
result))
Marc