Hello,
Goblins is using fibers as far as I understand. Fibers says that O_NONBLOCK should be set to every file descriptor being read or written to, for a fiber to correctly suspend.
The Guile manual on the other hand says that (ice-9 suspendable-ports) may be used for IO that suspends (to prompt) instead of blocking.
Can you please clarify what the correct order of doing things is? Should I use both O_NONBLOCK and suspendable ports together? I don’t see either fibers nor goblin use install-suspendable-ports!, except in tests/repl-driver.scm. I don’t understand how ^io works without using O_NONBLOCK. On the other hand, all the test I see in goblins that uses O_NONBLOCK relates to sockets; but what about the current input/output/error ports? For example, in an ncurses UI program, which is what I’m doing now…
Since Guile does not seem to use O_NONBLOCK in the Scheme source code of (ice-9 suspendable-ports) and since it does require a C shim as well, I assume that it’s the C-side that sets up O_NONBLOCK on stdin/stdout/stderr. So perhaps that suffices? But then, why is goblins not using suspendable-ports in ^io?
Edit: I believe that the answer is coming from “Non-Blocking I/O” in the Guile manual, but essentially it is this:
- Use
(ice-9 suspendable-ports)and call(install-suspendable-ports). - Set
O_NONBLOCKto current input/output/error (if desired) and to every subsequent port you open. - Now you can use
^iowith them and/or fibers.
I think this should be documented a bit more carefully in the ^io page, is there a reason why it’s not? I can only guess that maybe the hope was that goblins would support more than the fibers scheduler?
Edit 2: The Guile manual on non-blocking I/O also mentions at the end that Guile does not currently include an implementation of the facility to suspend the current thread, and links to 8sync, has that been superseded by Fibers? I see the latest commit is from 2021. I wonder if the Guile manual should be changed in that section? @cwebber
Edit 3: Apparently I should have ncurses I/O in a dedicated thread because it wouldn’t work right with O_NONBLOCK on stdin; or I need to figure out an alternative to correctly suspend. A bit overwhelming right now, I would appreciate all hints.