The issue is that boost::asio uses tss_ptr a lot while calling detail::thread_context::top_of_thread_call_stack, and this can lead to segfaults.
It looks like a workaround is to force the compiler not to cache the address of the thread_local, effectively always getting the current thread's tss. Stack overflow has a good discussion of it here, where the noinline attribute does the heavy lifting, looking something like:
When using boost::fiber with fibers with boost::asio, sometimes we get segfaults because the tss usage inside asio is not fiber-tolerant.
For reference, boost::fiber warns of this, saying "it would be problematic to migrate a fiber that relies on thread-local storage."
The issue is that boost::asio uses tss_ptr a lot while calling
detail::thread_context::top_of_thread_call_stack
, and this can lead to segfaults.It looks like a workaround is to force the compiler not to cache the address of the thread_local, effectively always getting the current thread's tss. Stack overflow has a good discussion of it here, where the noinline attribute does the heavy lifting, looking something like:
edit: noinline may be the right way to go, I'll test this out locally