Skip to content

Make _Py_ThreadId() work on PowerPC, IBM Z, etc. #112535

Closed
@colesbury

Description

@colesbury

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:

  1. We should use __builtin_thread_pointer() when available
  2. 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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions