With the C++0x feature of exception_ptr one can store an exception in one thread and have another thread access it. However, the other thread has to call rethrow_exception(). In some cases, however, I need to actually interrupt the other thread and have the exception be raised there immediately; polling the exception_ptr for non-null is not a solution.
I found a solution for how to inject an exception in Windows at http://www.codeproject.com/KB/exception/ExcInject.aspx by suspending a thread and modifying its instruction pointer register before resuming it. However, I also need my code to run on Linux. How do I accomplish it there?
If I use something like getcontext(), that gets the current thread's context (whereas in Windows, GetContext() accepts a thread parameter), so I would have to call it in a signal handler. But I've read that getcontext()/setcontext() should not be called in signal handlers... Alternatively, I could call rethrow_exception() directly in the signal handler, but I'm worried this won't have the intended effect, where the interrupted thread has the stack unwound in the same way with all destructors of the scope the interruption was in called etc.