LWN.net Logo

Re: getcontext/setcontext alternatives

Re: getcontext/setcontext alternatives

Posted May 9, 2012 2:53 UTC (Wed) by scottt (subscriber, #5028)
In reply to: Coroutines by wahern
Parent article: nPth - The new GNU portable threads library

A few questions:

  1. On which architecture did you run into the "thread-local-storage breaks when code trying to access a TLS object is run on a stack created with makecontext" problem?
  2. What's the alternative to getcontext() and friends? Going back to manually writing per arch "stack switching" code like cgreenlet/greenlet-asm.S?
I'm aware that {make,get,set}context() are considered deprecated and were only recently implemented in the glibc ARM port but they're still in use in some reasonably popular apps like the VNC server implementation in qemu etc.


(Log in to post comments)

Re: getcontext/setcontext alternatives

Posted May 9, 2012 11:20 UTC (Wed) by geertj (subscriber, #4116) [Link]

> What's the alternative to getcontext() and friends? Going back to manually
> writing per arch "stack switching" code like cgreenlet/greenlet-asm.S?

One trick that is sometimes used is sigaltstack() + setjmp(). However i would argue this is actually less portable than writing assembly (the assembly you refer to above is not OS specific, it is only architecture specific and the same function it works on Linux, Mac OSX and Windows).

In the best case, we would get a working and not-deprecated makecontext() function from libc at some point. Also we would need to get an extended longjmp() that allows for code injection in the target co-routine (for propagating exceptions in C++).

Re: getcontext/setcontext alternatives

Posted May 11, 2012 23:53 UTC (Fri) by jwakely (subscriber, #60262) [Link]

Can std::current_exception and std::rethrow_exception be used for that exception propagation or are they insufficient?

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds