Skip to content

Commit 3798bed

Browse files
committed
Add mutex for get_reftotal
1 parent 2bb60d9 commit 3798bed

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Objects/object.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ get_reftotal(PyInterpreterState *interp)
118118
since we can't determine which interpreter updated it. */
119119
Py_ssize_t total = REFTOTAL(interp);
120120
#ifdef Py_GIL_DISABLED
121+
INTERP_HEAD_LOCK(interp);
121122
for (PyThreadState *p = interp->threads.head; p != NULL; p = p->next) {
122123
/* This may race with other threads modifications to their reftotal */
123124
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)p;
124125
total += _Py_atomic_load_ssize_relaxed(&tstate_impl->reftotal);
125126
}
127+
INTERP_HEAD_UNLOCK(interp);
126128
#endif
127129
return total;
128130
}

0 commit comments

Comments
 (0)