Skip to content
Open
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions Doc/c-api/set.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
actually iterable. The constructor is also useful for copying a set
(``c=set(s)``).

.. note::

The operation is atomic on :term:`free threading <free-threaded build>`

Check warning on line 97 in Doc/c-api/set.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:class reference target not found: frozendict [ref.class]
when *iterable* is a :class:`set`, :class:`frozenset`, :class:`dict` or :class:`frozendict`.


.. c:function:: PyObject* PyFrozenSet_New(PyObject *iterable)

Expand All @@ -100,6 +105,11 @@
set on success or ``NULL`` on failure. Raise :exc:`TypeError` if *iterable* is
not actually iterable.

.. note::

The operation is atomic on :term:`free threading <free-threaded build>`

Check warning on line 110 in Doc/c-api/set.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:class reference target not found: frozendict [ref.class]
when *iterable* is a :class:`set`, :class:`frozenset`, :class:`dict` or :class:`frozendict`.


The following functions and macros are available for instances of :class:`set`
or :class:`frozenset` or instances of their subtypes.
Expand Down Expand Up @@ -127,6 +137,10 @@
the *key* is unhashable. Raise :exc:`SystemError` if *anyset* is not a
:class:`set`, :class:`frozenset`, or an instance of a subtype.

.. note::

The operation is atomic on :term:`free threading <free-threaded build>`
when *key* is :class:`str`, :class:`int`, :class:`float`, :class:`bool` or :class:`bytes`.

.. c:function:: int PySet_Add(PyObject *set, PyObject *key)

Expand All @@ -138,6 +152,12 @@
:exc:`SystemError` if *set* is not an instance of :class:`set` or its
subtype.

.. note::

The operation is atomic on :term:`free threading <free-threaded build>`
when *key* is :class:`str`, :class:`int`, :class:`float`, :class:`bool` or :class:`bytes`.



The following functions are available for instances of :class:`set` or its
subtypes but not for instances of :class:`frozenset` or its subtypes.
Expand All @@ -152,6 +172,11 @@
temporary frozensets. Raise :exc:`SystemError` if *set* is not an
instance of :class:`set` or its subtype.

.. note::

The operation is atomic on :term:`free threading <free-threaded build>`
when *key* is :class:`str`, :class:`int`, :class:`float`, :class:`bool` or :class:`bytes`.


.. c:function:: PyObject* PySet_Pop(PyObject *set)

Expand All @@ -167,6 +192,12 @@
success. Return ``-1`` and raise :exc:`SystemError` if *set* is not an instance of
:class:`set` or its subtype.

.. note::

In the :term:`free-threaded build`, the set is emptied before its entries
are cleared, so other threads will observe an empty set rather than
intermediate states.


Deprecated API
^^^^^^^^^^^^^^
Expand Down
23 changes: 23 additions & 0 deletions Doc/data/threadsafety.dat
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,29 @@ PyByteArray_GET_SIZE:atomic:
PyByteArray_AsString:compatible:
PyByteArray_AS_STRING:compatible:

# Creation - may iterate the iterable argument, calling arbitrary code.
# Atomic for sets, frozensets, dicts, and frozendicts.
PySet_New:shared:
PyFrozenSet_New:shared:

# Size - uses atomic load on free-threaded builds
PySet_Size:atomic:
PySet_GET_SIZE:atomic:

# Contains - lock-free, atomic with simple types
PySet_Contains:shared:

# Mutations - hold per-object lock for duration
# atomic with simple types
PySet_Add:shared:
PySet_Discard:shared:

# Pop - hold per-object lock for duration
PySet_Pop:atomic:

# Clear - empties the set before clearing
PySet_Clear:atomic:

# Capsule objects (Doc/c-api/capsule.rst)

# Type check - read ob_type pointer, always safe
Expand Down
Loading