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-111924: Use PyMutex for runtime global locks. #112207

Merged
merged 4 commits into from
Dec 7, 2023

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Nov 17, 2023

This replaces some usages of PyThread_type_lock with PyMutex, which does not require memory allocation to initialize.

This simplifies some of the runtime initialization and is also one step towards avoiding changing the default raw memory allocator during initialize/finalization, which can be non-thread-safe in some circumstances.

This replaces some usages of PyThread_type_lock with PyMutex, which
does not require memory allocation to initialize.
@colesbury
Copy link
Contributor Author

@ericsnowcurrently, when you get a chance, would you please review this?

PyMutex_Lock() behaves similarly to PyThread_acquire_lock() except that PyMutex_Lock() will temporarily release the GIL if it needs to block. That's mostly fine, but I think not what we want for the HEAD_LOCK() macro, so that explicitly passes a flag to not release the GIL (or detach in --disable-gil builds).

@brettcannon brettcannon removed their request for review November 17, 2023 20:25
Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

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

mostly LGTM

I've left a few very minor comments.

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

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

LGTM

I've left one comment that I'll leave to your discretion. I'll wait for your response before merging.

@ericsnowcurrently ericsnowcurrently merged commit cf6110b into python:main Dec 7, 2023
@ericsnowcurrently
Copy link
Member

Thanks for tackling this, @colesbury!

@colesbury colesbury deleted the global_locks branch December 12, 2023 19:37
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
This replaces some usages of PyThread_type_lock with PyMutex, which does not require memory allocation to initialize.

This simplifies some of the runtime initialization and is also one step towards avoiding changing the default raw memory allocator during initialize/finalization, which can be non-thread-safe in some circumstances.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
This replaces some usages of PyThread_type_lock with PyMutex, which does not require memory allocation to initialize.

This simplifies some of the runtime initialization and is also one step towards avoiding changing the default raw memory allocator during initialize/finalization, which can be non-thread-safe in some circumstances.
colesbury pushed a commit that referenced this pull request Dec 12, 2024
…GH-127866)

This PR fixes the build issue introduced by the commit 628f6eb from
GH-112207 on systems without thread local support.
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 12, 2024
…upport (pythonGH-127866)

This PR fixes the build issue introduced by the commit 628f6eb from
pythonGH-112207 on systems without thread local support.
(cherry picked from commit f823910)

Co-authored-by: velemas <10437413+velemas@users.noreply.github.com>
colesbury pushed a commit that referenced this pull request Dec 12, 2024
…support (GH-127866) (GH-127882)

This PR fixes the build issue introduced by the commit 628f6eb from
GH-112207 on systems without thread local support.
(cherry picked from commit f823910)

Co-authored-by: velemas <10437413+velemas@users.noreply.github.com>
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
…upport (pythonGH-127866)

This PR fixes the build issue introduced by the commit 628f6eb from
pythonGH-112207 on systems without thread local support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) skip news topic-free-threading
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants