Skip to content

Commit dc978f6

Browse files
authored
gh-112050: Make collections.deque thread-safe in free-threaded builds (#113830)
Use critical sections to make deque methods that operate on mutable state thread-safe when the GIL is disabled. This is mostly accomplished by using the @critical_section Argument Clinic directive, though there are a few places where this was not possible and critical sections had to be manually acquired/released.
1 parent 4742047 commit dc978f6

File tree

4 files changed

+338
-61
lines changed

4 files changed

+338
-61
lines changed

Include/internal/pycore_pyatomic_ft_wrappers.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ extern "C" {
2020
#endif
2121

2222
#ifdef Py_GIL_DISABLED
23+
#define FT_ATOMIC_LOAD_SSIZE(value) _Py_atomic_load_ssize(&value)
2324
#define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) \
2425
_Py_atomic_load_ssize_relaxed(&value)
2526
#define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) \
2627
_Py_atomic_store_ssize_relaxed(&value, new_value)
2728
#else
29+
#define FT_ATOMIC_LOAD_SSIZE(value) value
2830
#define FT_ATOMIC_LOAD_SSIZE_RELAXED(value) value
2931
#define FT_ATOMIC_STORE_SSIZE_RELAXED(value, new_value) value = new_value
3032
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make methods on :class:`collections.deque` thread-safe when the GIL is disabled.

0 commit comments

Comments
 (0)