Skip to content

Commit e059aa6

Browse files
authored
gh-120973: Fix thread-safety issues with threading.local (#121655)
This is a small refactoring to the current design that allows us to avoid manually iterating over threads. This should also fix gh-118490.
1 parent 2009e25 commit e059aa6

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)