If you ever want to allow parking a fiber with a native method on the stack

Stephane Epardaud stef at epardaud.fr
Wed Aug 8 09:18:23 UTC 2018


I've done this before in a Scheme VM that ran fibers-like threads. The
trick was to mark native methods that are reentrant (call back into
non-native code) so that they get executed in an alternate stack when
called by a fiber. The fiber would then wait for the native method to
either return or reenter and continue from there, in both cases with its
own stack clean. If that native call reentered you can mark the fiber
stack to remember it, and proceed. When you copy the fiber stack you
will copy the markers too and leave the delegate native stacks alone.
And when the fiber needs to pop back to the reentring native call you do
the same dance in reverse.

So, it can be done, but it requires marking reentrant native calls (you
can't easily detect that it reenters after you let it start on your
stack — well you can, but it's dirty) and starting them in alternate
stacks (or threads) which makes them more expensive (sync required).

Now, I'm not saying it _needs_ to be done, because it remains to be seen
if that'd really be useful.

Cheers.



More information about the loom-dev mailing list