Quick question on thread-interrupt! Marc Nieper-Wißkirchen (07 Nov 2022 09:41 UTC)
Re: Quick question on thread-interrupt! Marc Feeley (07 Nov 2022 18:19 UTC)
Re: Quick question on thread-interrupt! Marc Nieper-Wißkirchen (07 Nov 2022 18:43 UTC)
Re: Quick question on thread-interrupt! Marc Feeley (07 Nov 2022 20:08 UTC)
Re: Quick question on thread-interrupt! Marc Feeley (07 Nov 2022 20:28 UTC)
Re: Quick question on thread-interrupt! Marc Nieper-Wißkirchen (08 Nov 2022 07:27 UTC)
Re: Quick question on thread-interrupt! Marc Feeley (08 Nov 2022 15:00 UTC)
Re: Quick question on thread-interrupt! Marc Nieper-Wißkirchen (08 Nov 2022 15:58 UTC)
Re: Quick question on thread-interrupt! Marc Nieper-Wißkirchen (09 Nov 2022 12:15 UTC)
Re: Quick question on thread-interrupt! Marc Nieper-Wißkirchen (11 Nov 2022 11:24 UTC)
Re: Quick question on thread-interrupt! Marc Feeley (07 Nov 2022 20:36 UTC)

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