Skip to content

Conversation

@colesbury
Copy link
Contributor

@colesburycolesbury commented Mar 7, 2024

If a thread blocks while waiting on the shared->mutex lock, the array of QSBR states may be reallocated. In other words, the value oftstate->qsbr may be different before and after the PyMutex_Lock() call, and using the previous value across the lock acquisition is not safe.

If a thread blocks while waiting on the `shared->mutex` lock, the array of QSBR states may be reallocated. The `tstate->qsbr` values before the lock is acquired may not be the same as the value after the lock is acquired.
@colesburycolesbury requested a review from DinoVMarch 7, 2024 23:02
colesbury added a commit to colesbury/cpython that referenced this pull request Mar 7, 2024
In general, when `_PyThreadState_GET()` is non-NULL then the current thread is "attached", but there is a small window during `PyThreadState_DeleteCurrent()` where that's not true: tstate_delete_common is called when the thread is detached, but before current_fast_clear(). This updates _PySemaphore_Wait() to handle that case.
Copy link
Member

@corona10corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@colesburycolesbury merged commit cca3023 into python:mainMar 8, 2024
@colesburycolesbury deleted the gh-115103-unregister branch March 8, 2024 17:39
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
If a thread blocks while waiting on the `shared->mutex` lock, the array of QSBR states may be reallocated. The `tstate->qsbr` values before the lock is acquired may not be the same as the value after the lock is acquired.
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
If a thread blocks while waiting on the `shared->mutex` lock, the array of QSBR states may be reallocated. The `tstate->qsbr` values before the lock is acquired may not be the same as the value after the lock is acquired.
Sign up for freeto 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.

2 participants

@colesbury@corona10