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

Add variant of Py_BEGIN_CRITICAL_SECTION that accepts a NULL argument #115432

Closed
colesbury opened this issue Feb 13, 2024 · 1 comment
Closed
Assignees
Labels
topic-free-threading type-feature A feature request or enhancement

Comments

@colesbury
Copy link
Contributor

colesbury commented Feb 13, 2024

Feature or enhancement

We should add a variant of Py_BEGIN_CRITICAL_SECTION / Py_END_CRITICAL_SECTION that accepts a possibly NULL object. If the passed object is NULL then nothing is locked or unlocked. Otherwise, it behaves like Py_BEGIN_CRITICAL_SECTION.

For example:

PyObject *object = maybe ? real_object : NULL;
Py_XBEGIN_CRITICAL_SECTION(object);
...
Py_XEND_CRITICAL_SECTION();

This will be useful in making set thread-safe. There are a number of functions that take an optional iterable that may be NULL. We want to lock it in the cases where it's not NULL.

I don't think we will need a version of Py_BEGIN_CRITICAL_SECTION2 that accepts optionally NULL arguments.

Linked PRs

@colesbury colesbury added type-feature A feature request or enhancement topic-free-threading labels Feb 13, 2024
colesbury added a commit to colesbury/cpython that referenced this issue Feb 13, 2024
This adds `Py_BEGIN_CRITICAL_SECTION_OPT` and
`Py_END_CRITICAL_SECTION_OPT`, which accept a possibly NULL object as an
argument. If the argument is NULL, then nothing is locked or unlocked.
Otherwise, they behave like `Py_BEGIN/END_CRITICAL_SECTION`.
colesbury added a commit that referenced this issue Feb 15, 2024
…115433)

This adds `Py_XBEGIN_CRITICAL_SECTION` and
`Py_XEND_CRITICAL_SECTION`, which accept a possibly NULL object as an
argument. If the argument is NULL, then nothing is locked or unlocked.
Otherwise, they behave like `Py_BEGIN/END_CRITICAL_SECTION`.
@colesbury colesbury self-assigned this Mar 19, 2024
@colesbury colesbury reopened this Mar 19, 2024
@colesbury
Copy link
Contributor Author

It turns out that we are not using this in set (or anywhere else), so I think we should revert the PR.

diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…ect (python#115433)

This adds `Py_XBEGIN_CRITICAL_SECTION` and
`Py_XEND_CRITICAL_SECTION`, which accept a possibly NULL object as an
argument. If the argument is NULL, then nothing is locked or unlocked.
Otherwise, they behave like `Py_BEGIN/END_CRITICAL_SECTION`.
colesbury added a commit to colesbury/cpython that referenced this issue May 9, 2024
…NULL object (python#115433)"

This reverts commit ad4f909.

The API ended up not being used.
colesbury added a commit that referenced this issue May 9, 2024
…bject (#115433)" (#118861)

This reverts commit ad4f909.

The API ended up not being used.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 9, 2024
…NULL object (pythonGH-115433)" (pythonGH-118861)

This reverts commit ad4f909.

The API ended up not being used.
(cherry picked from commit 46c8081)

Co-authored-by: Sam Gross <colesbury@gmail.com>
colesbury added a commit that referenced this issue May 9, 2024
… NULL object (GH-115433)" (GH-118861) (#118872)

This reverts commit ad4f909.

The API ended up not being used.
(cherry picked from commit 46c8081)

Co-authored-by: Sam Gross <colesbury@gmail.com>
SonicField pushed a commit to SonicField/cpython that referenced this issue May 10, 2024
…NULL object (python#115433)" (python#118861)

This reverts commit ad4f909.

The API ended up not being used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-free-threading type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant