Ucontext and local thread storage

The platform I'm asking for is Linux. Local storage stream I'm talking about pthread_xxx or __thread in gcc.

I want to use ucontext, i.e. makecontext, swapcontext, etc. in my program. So my question is: how does it work with local thread storage? More specifically, if I switch to another fiber using swapcontext or setcontext, will the local stream store change or is the local stream store not part of the context?

Another question: if TLS is changed to setcontext / swapcontext , is there anything that sticks to the thread, no matter how I change the context? On the other hand, if TLS sticks to the context, is there anything that sticks to the stream and isn't changed using setcontext / swapcontext?

According to http://en.wikipedia.org/wiki/Fiber_ (computer_science) , the Windows platform has thread-based local storage and fiber storage.

+4
source share
1 answer

It is not clear how the local thread store interacts with setcontext / swapcontext.

On Linux, setconcon / swapcontext is not affected by local thread storage, and some software relies on this behavior - see a recent discussion on the netbsd mailing list for further understanding: swapcontext () around pthreads

Some thoughts on the interaction of TLS with parallelism in C ++ are also related: TLS_and_Parallelism.pdf

Change It is also worth noting that makecontext / swapcontext has been removed from the Open Group Base Spec Issue 7, as they have been flagged as deprecated for some time. As an alternative, Boost.Context has recently been added to Boost libraries (although it also does not support fiber storage).

+2
source

Source: https://habr.com/ru/post/1433710/


All Articles