Skip to content
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

gh-114940: Add a Per-Interpreter Lock For the List of Thread States #127115

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrently ericsnowcurrently commented Nov 21, 2024

The new lock may be used instead of the global "HEAD" lock. That global lock guards the list of interpreters, but unfortunately in some situations (like for interp->threads.head) it has been used as a generic "lock everything". This change helps us move away from that situation.

Note that there are 3 places in pystate.c where we have left HEAD_LOCK()/HEAD_UNLOCK() in place:

  • interpreter_clear()
  • new_threadstate()
  • tstate_delete_common()

Otherwise we end up breaking a constraint on free-threaded builds.

Co-authored-by: RUANG (James Roy) [email protected]

@ericsnowcurrently
Copy link
Member Author

There's a bit of code in tstate_delete_common() to avoid a deadlock, but I'm sure it isn't right. It probably makes sense to use a recursive lock here. I'm going to look more closely.

@ericsnowcurrently
Copy link
Member Author

Ideally we could build on top of gh-127121 for the recursive lock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant