-
-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make _Py_ThreadId() work on PowerPC, IBM Z, etc.
#112535
Comments
|
@colesbury Can I take a look at it? |
|
@corona10 - of course, thanks! |
That's fine. We have many tests preprocessor checks like that, |
Add also test.support.Py_GIL_DISABLED constant.
Add also test.support.Py_GIL_DISABLED constant.
Add also test.support.Py_GIL_DISABLED constant.
Add also test.support.Py_GIL_DISABLED constant.
Add also test.support.Py_GIL_DISABLED constant.
|
@colesbury Do we need to support more platforms or we can close the issue? |
|
I think we still want the cross-platform fallback that returns the address of a thread-local variable. That will probably need to be implemented in a |
|
FYI, PEP 11 defines which platform we should cover :) |
|
Adding a fallback will ease the maintenance burden and also work with WASM. In general, I think we want portable implementations when possible even if the platforms listed in PEP 11 ought to work without them. We can't use |
|
cpython/Python/thread_pthread.h Lines 380 to 406 in 7595d47
Well, we already implemented |
|
@corona10, no I don't think we should use |
|
Got it, I will send a PR soon. I read TLS spec in here and now I understand what you want to say.(maybe?) |
|
@corona10, here is an example of what I mean in mimalloc, which uses the same strategy on platforms where it doesn't implement a faster
cpython/Include/internal/mimalloc/mimalloc/prim.h Lines 224 to 226 in 9cdf05b
My reasons for preferring this strategy instead of
|
|
You may have a look at |
I am going to submit the PR early next week :) |
Update _Py_ThreadId() to support RISC-V
…3084) Update _Py_ThreadId() to support RISC-V
…3185) --------- Co-authored-by: Sam Gross <colesbury@gmail.com>
|
Okay, let's close the issue since the fallback implementation is merged. Now, we can support free-threaded CPython for all platforms where the fallback implementation(it only requires thread-local feature) works! |
…ythongh-113185) --------- Co-authored-by: Sam Gross <colesbury@gmail.com>
Add also test.support.Py_GIL_DISABLED constant.
…3084) Update _Py_ThreadId() to support RISC-V
…ythongh-113185) --------- Co-authored-by: Sam Gross <colesbury@gmail.com>
See python/cpython#112535 And python/cpython#112624 And python/cpython#112751 Rather than backporting a handful of small commits, let's wait for the next release.
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
The text was updated successfully, but these errors were encountered: