Re: coop - a concurrent ml-like wanna be (pre-SRFI)
Marc Feeley 06 May 2021 17:07 UTC
> On May 6, 2021, at 10:49 AM, Amirouche <xxxxxx@hyper.dev> wrote:
>
>
> On 2021-05-06 16:26, Marc Feeley - feeley at iro.umontreal.ca wrote:
>> I’m not sure what your goal is with this SRFI. Could you clarify?
>> SRFI-18 (Multithreading support) is supported by many Scheme
>> implementations and is the best thread API if you are interested in
>> portability accross Scheme implementations. It seems some of the
>> things you are proposing have a direct link with SRFI-18 features, so
>> I don’t understand why a new SRFI is needed.
>
> So far, if we disregard PRIORITY, coop is only an alternative to SRFI-18.
>
> When priority is +inf.0 it should have exclusive access to a CPU.
> Otherwise it is a hint to implement fairness.
Have you looked at SRFI-21, which adds priorities to SRFI-18? Note that few Scheme systems implement SRFI-21 because priorities require a carefully designed thread scheduler (as far as I know only Gambit implements SRFI-21). So I doubt the priorities of coop can be implemented portably.
If channels are an important feature of coop please try to see if “mailboxes” can be used instead. They are implemented by several Scheme implementations that support SRFI-18. Here’s a simple example with Gambit (should also work as-is with Racket):
(define t (thread
(lambda ()
(let loop ()
(let ((m (thread-receive))) (thread-send (car m) (sqrt (cadr m))))
(loop)))))
(thread-send t (list (current-thread) 10)) ;; request sqrt of 10
(thread-receive) ;; => 3.1622776601683795
Marc