cpython/Lib/test/test_free_threading
Pieter Eendebak 7e38e6745d
gh-123271: Make builtin zip method safe under free-threading (#123272)
The `zip_next` function uses a common optimization technique for methods
that generate tuples. The iterator maintains an internal reference to
the returned tuple. When the method is called again, it checks if the
internal tuple's reference count is 1. If so, the tuple can be reused.
However, this approach is not safe under the free-threading build:
after checking the reference count, another thread may perform the same
check and also reuse the tuple. This can result in a double decref on
the items of the replaced tuple and a double incref (memory leak) on
the items of the tuple being set.

This adds a function, `_PyObject_IsUniquelyReferenced` that
encapsulates the stricter logic necessary for the free-threaded build:
the internal tuple must be owned by the current thread, have a local
refcount of one, and a shared refcount of zero.
2024-08-27 15:22:43 -04:00
..
__init__.py
test_dict.py
test_list.py
test_monitoring.py
test_slots.py
test_str.py
test_tokenize.py gh-120317: Lock around global state in the tokenize module (#120318) 2024-07-16 11:35:57 +02:00
test_type.py
test_zip.py gh-123271: Make builtin zip method safe under free-threading (#123272) 2024-08-27 15:22:43 -04:00