Skip to content

enhance docs for critical sections #137334

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Aug 3, 2025

@bedevere-app bedevere-app bot added the docs Documentation in the Doc dir label Aug 3, 2025
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Aug 3, 2025
@kumaraditya303 kumaraditya303 marked this pull request as ready for review August 4, 2025 10:33
:class:`list` and :class:`dict` because their public C-APIs
already use critical sections internally, with the notable
exception of :c:func:`PyDict_Next`, which requires critical section
to be acquired externally.
Copy link
Contributor

@ngoldbaum ngoldbaum Aug 4, 2025

Choose a reason for hiding this comment

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

I'm not sure if I agree here. Unless I've done something wrong in NumPy. I handled this for lists using the PySequence API. I take a critical section on a list, convert to a sequence using PySequence_Fast, and then operate on the sequence under a critical section. The sequence APIs also bypass the internal critical sections and they're documented not to be thread-safe, so I think this is actually the only safe way to use PySequence_Fast correctly on the free-threaded build.

* Calling :c:func:`PyEval_SaveThread` to detach the current thread.
* Recursively entering the critical section for the same object.
Copy link
Contributor

Choose a reason for hiding this comment

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

In 3.14, don't recursive critical sections not get suspended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it isn't exactly recursive, there is one more condition which is that the critical section should be the topmost held critical section otherwise it can still get suspended

* Calling :c:func:`PyEval_SaveThread` to detach the current thread.
* Recursively entering the critical section for the same object.
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be worth mentioning that these are exactly the same guarantees provided by the GIL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy