diff options
| author | Sam Gross <colesbury@gmail.com> | 2024-06-03 20:58:41 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-03 20:58:41 (GMT) |
| commit | 47fb4327b5c405da6df066dcaa01b7c1aefab313 (patch) | |
| tree | 8b5e04508b3cdced61e56eb200c4fc46a50ed11d /Python/bltinmodule.c | |
| parent | b8fde5db86334690da23343f5f4326adcd8160fb (diff) | |
| download | cpython-47fb4327b5c405da6df066dcaa01b7c1aefab313.zip cpython-47fb4327b5c405da6df066dcaa01b7c1aefab313.tar.gz cpython-47fb4327b5c405da6df066dcaa01b7c1aefab313.tar.bz2 | |
gh-117657: Fix race involving immortalizing objects (#119927)
The free-threaded build currently immortalizes objects that use deferred
reference counting (see gh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.
This fixes a race condition involving the tracking of whether the
behavior is suppressed.
Diffstat (limited to 'Python/bltinmodule.c')
| -rw-r--r-- | Python/bltinmodule.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 2a02d81..c4d3ecb 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -870,15 +870,15 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, // gh-118527: Disable immortalization of code constants for explicit // compile() calls to get consistent frozen outputs between the default // and free-threaded builds. + // Subtract two to suppress immortalization (so that 1 -> -1) PyInterpreterState *interp = _PyInterpreterState_GET(); - int old_value = interp->gc.immortalize.enable_on_thread_created; - interp->gc.immortalize.enable_on_thread_created = 0; + _Py_atomic_add_int(&interp->gc.immortalize, -2); #endif result = Py_CompileStringObject(str, filename, start[compile_mode], &cf, optimize); #ifdef Py_GIL_DISABLED - interp->gc.immortalize.enable_on_thread_created = old_value; + _Py_atomic_add_int(&interp->gc.immortalize, 2); #endif Py_XDECREF(source_copy); |
