Skip to content

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

Open
ericsnowcurrently wants to merge 5 commits into
python:mainfrom
ericsnowcurrently:interp-threads-lock-2
Open

gh-114940: Add a Per-Interpreter Lock For the List of Thread States#127115
ericsnowcurrently wants to merge 5 commits into
python:mainfrom
ericsnowcurrently:interp-threads-lock-2

Conversation

@ericsnowcurrently

@ericsnowcurrentlyericsnowcurrently commented Nov 21, 2024

Copy link
Copy Markdown
Member

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) longjinyii@outlook.com

@ericsnowcurrently

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

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

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label Apr 19, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core reviewskip newsstaleStale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@ericsnowcurrently