8000 GH-102126: fix deadlock at shutdown when clearing thread states by kumaraditya303 · Pull Request #102222 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-102126: fix deadlock at shutdown when clearing thread states #102222

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

Merged
merged 3 commits into from
Feb 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix deadlock with reentrant calls to get head lock
  • Loading branch information
kumaraditya303 committed Feb 24, 2023
commit 9ade043322fe6962ef5a0d772f22131bf66d4b37
12 changes: 9 additions & 3 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,18 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
_PyErr_Clear(tstate);
}

// Clear the current/main thread state last.
HEAD_LOCK(runtime);
// XXX Clear the current/main thread state last.
for (PyThreadState *p = interp->threads.head; p != NULL; p = p->next) {
PyThreadState *p = interp->threads.head;
HEAD_UNLOCK(runtime);
while (p != NULL) {
// Must be called without HEAD_LOCK held as it can deadlock
// if any finalizer tries to acquire that lock.
PyThreadState_Clear(p);
HEAD_LOCK(runtime);
p = p->next;
HEAD_UNLOCK(runtime);
}
HEAD_UNLOCK(runtime);

/* It is possible that any of the objects below have a finalizer
that runs Python code or otherwise relies on a thread state
Expand Down
0