gh-112529: Make the GC scheduling thread-safe (#114880)

The GC keeps track of the number of allocations (less deallocations)
since the last GC. This buffers the count in thread-local state and uses
atomic operations to modify the per-interpreter count. The thread-local
buffering avoids contention on shared state.

A consequence is that the GC scheduling is not as precise, so
"test_sneaky_frame_object" is skipped because it requires that the GC be
run exactly after allocating a frame object.
This commit is contained in:
Sam Gross 2024-02-16 11:22:27 -05:00 committed by GitHub
parent f92857a930
commit b24c9161a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 71 additions and 16 deletions

View file

@ -13,7 +13,7 @@ except ImportError:
_testcapi = None
from test import support
from test.support import threading_helper
from test.support import threading_helper, Py_GIL_DISABLED
from test.support.script_helper import assert_python_ok
@ -294,6 +294,7 @@ class TestIncompleteFrameAreInvisible(unittest.TestCase):
assert_python_ok("-c", code)
@support.cpython_only
@unittest.skipIf(Py_GIL_DISABLED, "test requires precise GC scheduling")
def test_sneaky_frame_object(self):
def trace(frame, event, arg):