>> It currently is difficult to write a correct implementation of get-bytevector-all in pure Scheme, because ‘get-bytevector-all’ needs to return a _fresh_ bytevector and could return twice (e.g. in case of system-async-mark + call-with-prompt shenanigans). I think the proposed implementation is incorrect in this way.

 

>Hmm I don’t see how it could return twice.  If an async runs while

>‘get-bytevector-all’ is executed, it cannot cause ‘get-bytevector-all’

>to abort to a prompt.  I think we’re fine, no?

 

I did not say that ‘get-bytevector-all’ aborts to a prompt. Rather, the async itself does the abort-to-prompt, and since the async is run inside the get-bytevector-all, as a result get-bytevector-all could return twice (depending on what the handler of call-with-prompt is doing with the delimited continuation).

 

I’m pretty sure it can do this, that’s how Fibers works (to be clear I’m referring to the abort-to-prompt from an async, not the return twice, Fibers doesn’t do return twice things) -- non-cooperative scheduling is implemented by aborting from an async.

 

Example (assuming bad/good timing):

 

Thread #1:

;; Consider the situation where the handler invokes the delimited continuation twice.

(call-with-prompt

  [tag + handler things]

  (lambda () (get-bytevector-all [...]))

  [tag + handler things])

 

Thread #2:

(system-async-mark

  (lambda ()

    (abort-to-prompt [tag + more arguments]))

 [Thread #1]))

Best regards,

Maxime Devos.