Skip to content

Commit c141748

Browse files
authored
gh-128691: Use deferred reference counting on _thread._local (#128693)
This change, along with the LOAD_ATTR specializations, makes the "thread_local_read" micro benchmark in Tools/ftscalingbench/ftscalingbench.py scale well to multiple threads.
1 parent 087bb48 commit c141748

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Modules/_threadmodule.c

+4
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,10 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
14141414
return NULL;
14151415
}
14161416

1417+
// gh-128691: Use deferred reference counting for thread-locals to avoid
1418+
// contention on the shared object.
1419+
_PyObject_SetDeferredRefcount((PyObject *)self);
1420+
14171421
self->args = Py_XNewRef(args);
14181422
self->kw = Py_XNewRef(kw);
14191423

0 commit comments

Comments
 (0)