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 explanation about @critical_section target directive #1246

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions development-tools/clinic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,36 @@ The generated glue code looks like this:
return return_value;
}

You can lock one or two additional objects
by supplying their C variable names as arguments
to the ``@critical_section`` directive.
This example from :cpy-file:`Modules/_weakref.c` takes
one additional argument (a C variable named ``object``)::

/*[clinic input]
@critical_section object
_weakref.getweakrefcount -> Py_ssize_t

object: object
corona10 marked this conversation as resolved.
Show resolved Hide resolved
/
Return the number of weak references to 'object'.
[clinic start generated code]*/

The generated glue code looks like this:

.. code-block:: c

static PyObject *
_weakref_getweakrefs(PyObject *module, PyObject *object)
{
PyObject *return_value = NULL;

Py_BEGIN_CRITICAL_SECTION(object);
return_value = _weakref_getweakrefs_impl(module, object);
Py_END_CRITICAL_SECTION();

return return_value;
}

.. versionadded:: 3.13

Expand Down
Loading