c/c++ coroutines with setcontext
schmorp at schmorp.de
Wed May 27 22:03:19 CEST 2009
On Mon, May 25, 2009 at 09:59:23AM +0100, James Mansion <james at mansionfamily.plus.com> wrote:
> Have you actually checked what the portability is of Steve Dekorte's code?
I checked it afterwards - it contains a lot of hardcoded hacks for specific
runtime library versions, and is therefore rather fragile.
It also apparently doesn't work around the issues on the bsds, so I expect ti
to fail there.
> I wouldn't like to infer that this stuff doesn't work just because a
> different coroutine system has some issues.
You don't need to, it doesn't work because it uses technology that has
known issues (setjmp, ucontext, naive stack switching...), as I have
> You can probably infer something about the portability of Steve's code from
> the presence of an io port on the platform.
I can't, because I have no clue what an io port is, in that context.
>> in fact, the only way to implement coroutines on freebsd and netbsd that I
>> found is using the native thread library (which on netbsd is only slightly
>> slower as the ucontetx functions, fortunately, as it's userspace).
> Note that this is out of date for NetBSD 5 and for default modern builds
> on FreeBSD.
Unfortunately, reality contradicts this (at least for netbsd 5, no clue
what version "default modern builds" is supposed to mean).
In any case, you may believe what you want from your inferences - I prefer
to test things, and from that, I know that setjmp/ucontext do not work on
any "modern builds" of netbsd/freebsd I tested - they work well on older
releases, though, due to the stack checking that was introduced, at least
when linking against -lpthread.
Of course, I infer from my past tests (locales, threading, ttys,
kqueue...) that any interface that hasn't been used before in exactly the
same way is likely being broken on bsd platforms, especially freebsd, but
then, some people prefer to test this, too :)
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / pcg at goof.com
More information about the libev