Boost logo

Boost :

Subject: Re: [boost] [context] review
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2011-03-27 09:22:52


Hello Gordon,

thank you for your review - getting input/opinion of other people helps
to shape the lib.

Am 27.03.2011 14:48, schrieb Gordon Woodhull:
> However, I do not have the expertise to pore over assembly instructions, nor do I know whether this is the right approach.
Assembler is the only way to access and set stack pointer, instruction
pointer and the other registers.

> I would probably be just as happy with a slower safe cross-platform library built on OS support, as with the fast (dangerous?) assembly version.
On UNIX ucontext_t is deprecated by the new POSIX standard (and might
not be available in the next releases of C-libs). This has its reason in
the fact that the interface of makecontext() function was
designed before C99. It expects a function-pointer of void(*)() and
accepts ellipses/var args for the arguments accepted by the function to
be called by ucontext_t.
I'm not the big C expert but I believe following cast is not legal (even
if some compilers accept it):

void my_fn( int, char *);
(void(*)())my_fn; // not legal

But the signature of ucontext-function makecontext( ucontext_t *,
void(*)(), int, ...) requires this cast.

Even worse - on x86_64/Linux the glibc the usage of non integer values
as argument for the var-args is undefined. example:

void my_fn( X * x); // to be called by ucontext

X * x = new X("abc");
ucontext_t ctx;
makecontext( & ctx, (void(*)())(my_fn), 1, x); // not reliable;
undefined behaviour

In the example above it might work (if the high bits of the address of x
are zero) but in some cases makecontext() truncates the high bit of x
pointer :/
=> segfault

Therefore I prefer the fcontext version over ucontext because it hasn't
this problem.

On Windows I suggest using the Windows Fiber version because as Holger
mentioned I've to correct the exception handling.

> I hope that people who know better, like Giovanni and Holger, will continue to help make the library more robust.

I hope it too :)

> I thought I had understood from discussion that the class is moveable, but this didn't work for me. I ended up having to wrap contexts up in shared_ptrs in order to get my example to work (attached).
>

It was a misunderstanding the in review version boost::context is
noncopyable - but it was in a previous version moveable (pimpl idiom).
I currently modify the lib so that boost::context supports move operations.

> The documentation is quite spare and completely lacks examples. It needs copy-editing (I can help there).

that would be really nice

regards,
Oliver


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk