diff options
author | Alex Turner <nerdscentral@googlemail.com> | 2024-04-29 20:26:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-29 20:26:26 (GMT) |
commit | 2ba1aed596ff9e7c5e193cf990f1f20f08bbf116 (patch) | |
tree | 3ca41cd50f53b7e8edde841a5c21f1ef3476be47 /Python | |
parent | 79688b5b0ea761183193ffb0859415f3b02fa44d (diff) | |
download | cpython-2ba1aed596ff9e7c5e193cf990f1f20f08bbf116.zip cpython-2ba1aed596ff9e7c5e193cf990f1f20f08bbf116.tar.gz cpython-2ba1aed596ff9e7c5e193cf990f1f20f08bbf116.tar.bz2 |
gh-117657: TSAN fix race on `gstate->young.count` (#118313)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/gc_free_threading.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c index 8c0940d..ef6aaad 100644 --- a/Python/gc_free_threading.c +++ b/Python/gc_free_threading.c @@ -1044,9 +1044,20 @@ record_deallocation(PyThreadState *tstate) } static void -gc_collect_internal(PyInterpreterState *interp, struct collection_state *state) +gc_collect_internal(PyInterpreterState *interp, struct collection_state *state, int generation) { _PyEval_StopTheWorld(interp); + + // update collection and allocation counters + if (generation+1 < NUM_GENERATIONS) { + state->gcstate->old[generation].count += 1; + } + + state->gcstate->young.count = 0; + for (int i = 1; i <= generation; ++i) { + state->gcstate->old[i-1].count = 0; + } + // merge refcounts for all queued objects merge_all_queued_objects(interp, state); process_delayed_frees(interp); @@ -1115,7 +1126,6 @@ error: static Py_ssize_t gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason) { - int i; Py_ssize_t m = 0; /* # objects collected */ Py_ssize_t n = 0; /* # unreachable objects that couldn't be collected */ PyTime_t t1 = 0; /* initialize to prevent a compiler warning */ @@ -1161,15 +1171,6 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason) PyDTrace_GC_START(generation); } - /* update collection and allocation counters */ - if (generation+1 < NUM_GENERATIONS) { - gcstate->old[generation].count += 1; - } - gcstate->young.count = 0; - for (i = 1; i <= generation; i++) { - gcstate->old[i-1].count = 0; - } - PyInterpreterState *interp = tstate->interp; struct collection_state state = { @@ -1177,7 +1178,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason) .gcstate = gcstate, }; - gc_collect_internal(interp, &state); + gc_collect_internal(interp, &state, generation); m = state.collected; n = state.uncollectable; |