Skip to content

Make _threadmodule.c thread-safe in --disable-gil builds #114271

Description

@mpage

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 existing PyThread_get_thread_ident().

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. mpage commented on Jan 19, 2024

    @mpage
    ContributorAuthor

    @colesbury - Would you assign this to me, please?

  2. added a commit that references this issue on Feb 5, 2024
  3. added a commit that references this issue on Feb 12, 2024
  4. added a commit that references this issue on Feb 14, 2024
  5. added a commit that references this issue on Feb 16, 2024
  6. added a commit that references this issue on Mar 1, 2024
  7. added a commit that references this issue on Mar 4, 2024
  8. 15 remaining items

  9. added a commit that references this issue on Mar 20, 2024
  10. added 3 commits that reference this issue on Mar 25, 2024
  11. colesbury commented on Apr 10, 2024

    @colesbury
    Contributor

    @mpage is this complete?

  12. mpage commented on Apr 10, 2024

    @mpage
    ContributorAuthor

    Yep. I filed #117721 to track the follow up work we discussed for _thread.lock.release().

  13. added 4 commits that reference this issue on Apr 17, 2024
  14. added a commit that references this issue on Nov 15, 2024
  15. added a commit that references this issue on Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions