On Fri, 11 Mar 2022 09:58:59 -0500 Olivier Dion <olivier.d...@polymtl.ca> wrote: > On Fri, 11 Mar 2022, Chris Vine <vine24683...@gmail.com> wrote: [snip] > > Avoid using get-bytevector-n!, get-bytevector-some and > > get-bytevector-all if you are going to use something like fibers or > > some other asynchronous i/o, as those procedures are not suspendable > > (they can block). get-bytevector-n (note the difference from > > get-bytevector-n!) and get-string-all are suspendable and should > > generally be preferred where suspension is required. > > I'm not sure this is related to the functions themself but instead the > underlying filedescriptor opened iwth ON_NONBLOCK?
The problem I am referring to is different: it is that delimited continuations cannot capture C code and ports are written in C. Suspendable specializations, written in pure scheme, of some of guile's i/o procedures are therefore provided in modules/ice-9/suspendable-ports.scm, which is a file worth reading on its own account, and which are brought into effect (by suppressing the C-based equivalents) by applying the install-suspendable-ports! procedure. If your i/o steps out of this set of primitives (see in particular the port-bindings variable in that file) then it is not suspendable. When suspendable ports were first introduced in guile-2.2.0, this safe set did not include get-bytevector-n!, get-bytevector-some, get-bytevector-some! and get-bytevector-all: I have just re-read the code in guile-2.2.0 to confirm this. I have also just checked with the latest versions of guile-2.2 and guile-3.0 and it appears that get-bytevector-n!, get-bytevector-some and get-bytevector-some! are now supported so it looks as if at some point since version 2.2.0 they have become OK. With guile-2.2.0, this in turn meant that amongst other things, http-get, http-put and so on could not normally be used in suspendable code. I would need to check whether that remains the case - I cannot now remember which calls they made which were forbidden to suspendable code. Notable procedures which it appears remain as non-suspendable are get-bytevector-all, get-string-n, read, write and display, but to be sure about the first two of those I would also need to read the source again. A few years ago I had some test code to test which procedures were suspendable and I will also have to see if I can find it again. Chris