Closed
Description
Feature or enhancement
Proposal:
Make the functionality in _threadmodule.c
thread-safe in free-threaded builds.
Commits from nogil-3.12: https://github.com/colesbury/nogil-3.12/commits/nogil-3.12/Modules/_threadmodule.c
Context from @colesbury:
- Ignore the CriticalLock commit; this was an idea that didn't work and was prone to deadlock.
- Ignore the weakrefs change.
- Unclear if we need to deal with _tstate_lock.
- For the other changes, use your judgement. You may be able to put together smaller changes
_Py_ThreadId()
is currently only available in the free-threaded build, so the recursive lock implementation can probably (?) just stick with the existingPyThread_get_thread_ident()
.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
- gh-114271: Fix race in
Thread.join()
#114839 - gh-114271: Make
PyInterpreterState.threads.count
thread-safe in free-threaded builds #115093 - gh-114271: Make
thread._rlock
thread-safe in free-threaded builds #115102 - gh-114271: Make
_thread.ThreadHandle
thread-safe in free-threaded builds #115190 - gh-114271: Make
_thread.lock
thread-safe in free-threaded builds #116433 - gh-114271: Clean Up _threadmodule.c #116776