mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-132917: Fix data race detected by tsan (#133508)
Fix data race detected by tsan
(4171271720
):
young.count can be modified by other threads even while the gcstate is
locked.
This is the simplest fix to (potentially) unblock beta 1, although this
particular code path seems like it could just be an atomic swap followed by
an atomic add, without having the lock at all.
This commit is contained in:
parent
296cd128bf
commit
53e6d76aa3
1 changed files with 2 additions and 3 deletions
|
@ -2074,10 +2074,9 @@ gc_should_collect_mem_usage(GCState *gcstate)
|
|||
// clear the young object count so we don't check memory usage again
|
||||
// on the next call to gc_should_collect().
|
||||
PyMutex_Lock(&gcstate->mutex);
|
||||
int young_count = _Py_atomic_exchange_int(&gcstate->young.count, 0);
|
||||
_Py_atomic_store_ssize_relaxed(&gcstate->deferred_count,
|
||||
gcstate->deferred_count +
|
||||
gcstate->young.count);
|
||||
_Py_atomic_store_int(&gcstate->young.count, 0);
|
||||
gcstate->deferred_count + young_count);
|
||||
PyMutex_Unlock(&gcstate->mutex);
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue