bpo-40522: Store tstate in a Thread Local Storage #23976
Conversation
Build fails on macOS with Clang 12.0.0 (clang-1200.0.32.27): "illegal thread local variable reference"
|
On MSC, we can try to use |
cc @markshannon who loves TLS :-) |
See https://bugs.python.org/issue40522#msg383899 for the emitted assembly code. |
"In C11, the keyword _Thread_local is used to define thread-local variables. The header <threads.h>, if supported, defines thread_local as a synonym for that keyword." |
If Python is built with GCC or clang, the current interpreter and the current Python thread state are now stored in a Thread Local Storage. Changes: * configure checks for C11 _Thread_local keyword. * Use _Thread_local keyword, GCC and clang __thread extension. * Add set_current_tstate() sub-function which sets these two new TLS variables (if available). * _PyThreadState_Swap() and _PyThreadState_DeleteCurrent() now call set_current_tstate(). * _PyThreadState_GET() and _PyInterpreterState_GET() now use the TLS variable if available.
Would it be possible to keep all the portability macros in one place by putting something like |
One other remark (not for this PR, but for future work): |
I need to test |
This PR is stale because it has been open for 30 days with no activity. |
If Python is built with GCC or clang, the current interpreter and the
current Python thread state are now stored in a Thread Local Storage.
Changes:
variables.
variables (if available).
set_current_tstate().
variable if available.
https://bugs.python.org/issue40522