Feature or enhancement
Currently, _Py_ThreadId() is only defined in Py_GIL_DISABLED builds and does not compile on PowerPC or IBM Z. It would be convenient to make the functionality available in general: it will be useful to implement thread-safe recursive locks. (Currently our recursive lock implementations rely on the GIL for thread-safety.)
There are two parts to this:
- We should use
__builtin_thread_pointer() when available
- We should fall back to a function that returns the address of a thread-local variable if no other fast implementation is available (instead of erroring out).
The fallback (2) will be a bit slower, but it provides a portable implementation.
Note that checking if __builtin_thread_pointer() is available is not trivial. __has_builtin(__builtin_thread_pointer) is not useful (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96952). You need some combination of platform and GCC/clang version check.
cc @vstinner @corona10
Linked PRs
Feature or enhancement
Currently,
_Py_ThreadId()is only defined inPy_GIL_DISABLEDbuilds and does not compile on PowerPC or IBM Z. It would be convenient to make the functionality available in general: it will be useful to implement thread-safe recursive locks. (Currently our recursive lock implementations rely on the GIL for thread-safety.)There are two parts to this:
__builtin_thread_pointer()when availableThe fallback (2) will be a bit slower, but it provides a portable implementation.
Note that checking if
__builtin_thread_pointer()is available is not trivial.__has_builtin(__builtin_thread_pointer)is not useful (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96952). You need some combination of platform and GCC/clang version check.cc @vstinner @corona10
Linked PRs