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 gh-120659: Skip `test_freethreading` with GIL (#120660) 2024-06-18 15:56:20 +02:00
test_dict.py gh-120579: Guard `_testcapi` import in `test_free_threading` (#120580) 2024-06-16 11:26:13 +03:00
test_list.py gh-118362: Skip tests when threading isn't available (#118666) 2024-05-06 16:45:04 -07:00
test_monitoring.py gh-118362: Skip tests when threading isn't available (#118666) 2024-05-06 16:45:04 -07:00
test_slots.py gh-117657: Fix `__slots__` thread safety in free-threaded build (#119368) 2024-06-17 18:44:54 +00:00
test_str.py gh-120417: Remove unused imports in tests (part 2) (#120630) 2024-06-17 21:05:37 +02:00
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 gh-120198: Stop the world when setting __class__ on free-threaded build (GH-120672) 2024-07-11 02:02:08 +08:00
test_zip.py gh-123271: Make builtin zip method safe under free-threading (#123272) 2024-08-27 15:22:43 -04:00