Skip to content

Commit bf7f4f3

Browse files
[3.13] gh-120973: Fix thread-safety issues with threading.local (GH-121655) (#122042)
This is a small refactoring to the current design that allows us to avoid manually iterating over threads. This should also fix gh-118490. (cherry picked from commit e059aa6) Co-authored-by: mpage <[email protected]>
1 parent 159ea47 commit bf7f4f3

File tree

3 files changed

+245
-150
lines changed

3 files changed

+245
-150
lines changed

Include/cpython/pystate.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ struct _ts {
192192
PyObject *previous_executor;
193193

194194
uint64_t dict_global_version;
195+
196+
/* Used to store/retrieve `threading.local` keys/values for this thread */
197+
PyObject *threading_local_key;
198+
199+
/* Used by `threading.local`s to be remove keys/values for dying threads.
200+
The PyThreadObject must hold the only reference to this value.
201+
*/
202+
PyObject *threading_local_sentinel;
195203
};
196204

197205
#ifdef Py_DEBUG

0 commit comments

Comments
 (0)