Skip to content

gh-117657: TSAN fix race on gstate->young.count #118313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Continuing to whack-a-mole TSAN issues found in No-GIL tests.
24 changes: 13 additions & 11 deletions Python/gc_free_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,20 @@
}

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 (size_t i = 1; i <= generation; ++i) {

Check warning on line 1051 in Python/gc_free_threading.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test

comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
state->gcstate->old[i-1].count = 0;
}

// merge refcounts for all queued objects
merge_all_queued_objects(interp, state);
process_delayed_frees(interp);
Expand Down Expand Up @@ -1109,7 +1120,7 @@
static Py_ssize_t
gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
{
int i;

Check warning on line 1123 in Python/gc_free_threading.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'i': unreferenced local variable [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1123 in Python/gc_free_threading.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'i': unreferenced local variable [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 1123 in Python/gc_free_threading.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test

unused variable ‘i’ [-Wunused-variable]
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 */
Expand Down Expand Up @@ -1155,23 +1166,14 @@
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 = {
.interp = interp,
.gcstate = gcstate,
};

gc_collect_internal(interp, &state);
gc_collect_internal(interp, &state, generation);

m = state.collected;
n = state.uncollectable;
Expand Down
1 change: 0 additions & 1 deletion Tools/tsan/suppressions_free_threading.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ race:_PyObject_GC_TRACK
race:_PyParkingLot_Park
race:_PyType_HasFeature
race:assign_version_tag
race:gc_collect_main
race:gc_restore_tid
race:initialize_new_array
race:insertdict
Expand Down
Loading