gh-114271: Make `_thread.lock` thread-safe in free-threaded builds by mpage · Pull Request #116433 · python/cpython · GitHub
Skip to content

gh-114271: Make _thread.lock thread-safe in free-threaded builds - #116433

Merged
colesbury merged 1 commit into
python:mainfrom
mpage:gh-114271-_thread-lock-partial
Mar 6, 2024
Merged

gh-114271: Make _thread.lock thread-safe in free-threaded builds#116433
colesbury merged 1 commit into
python:mainfrom
mpage:gh-114271-_thread-lock-partial

Conversation

@mpage

@mpage mpage commented Mar 6, 2024

Copy link
Copy Markdown
Contributor

Previously, the locked field was set after releasing the lock. This reverses the order so that the locked field is set while the lock is still held.

There is still one thread-safety issue where locked is checked prior to releasing the lock, however, in practice that will only be an issue when unlocking the lock is contended, which should be rare.

…in free-threaded builds

Previously, the `locked` field was set after releasing the lock. This reverses
the order so that the `locked` field is set while the lock is still held.

There is still one thread-safety issue where `locked` is checked prior to
releasing the lock, however, in practice that will only be an issue when
unlocking the lock is contended, which should be rare.

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@colesbury
colesbury merged commit c62144a into python:main Mar 6, 2024
@bedevere-bot

Copy link
Copy Markdown

@colesbury

Copy link
Copy Markdown
Contributor

adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
…lds (python#116433)

Previously, the `locked` field was set after releasing the lock. This reverses
the order so that the `locked` field is set while the lock is still held.

There is still one thread-safety issue where `locked` is checked prior to
releasing the lock, however, in practice that will only be an issue when
unlocking the lock is contended, which should be rare.
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…lds (python#116433)

Previously, the `locked` field was set after releasing the lock. This reverses
the order so that the `locked` field is set while the lock is still held.

There is still one thread-safety issue where `locked` is checked prior to
releasing the lock, however, in practice that will only be an issue when
unlocking the lock is contended, which should be rare.
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.

3 participants