Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address review: use seq-cst atomics for initialized flags
Not performance critical, so use the default ordering rather than
acquire/release.
  • Loading branch information
gpshead committed Mar 23, 2026
commit 01df0a2eced120b701a228e36ff3dbf611d45de6
12 changes: 6 additions & 6 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,27 @@ _PyRuntimeState_SetFinalizing(_PyRuntimeState *runtime, PyThreadState *tstate) {
}
}

// Release on store, acquire on load: a thread that reads initialized=1
// is guaranteed to observe all writes from the initialization sequence.
// Atomic so a thread that reads initialized=1 observes all writes
// from the initialization sequence (gh-146302).

static inline int
_PyRuntimeState_GetCoreInitialized(_PyRuntimeState *runtime) {
return _Py_atomic_load_int_acquire(&runtime->core_initialized);
return _Py_atomic_load_int(&runtime->core_initialized);
}

static inline void
_PyRuntimeState_SetCoreInitialized(_PyRuntimeState *runtime, int initialized) {
_Py_atomic_store_int_release(&runtime->core_initialized, initialized);
_Py_atomic_store_int(&runtime->core_initialized, initialized);
}

static inline int
_PyRuntimeState_GetInitialized(_PyRuntimeState *runtime) {
return _Py_atomic_load_int_acquire(&runtime->initialized);
return _Py_atomic_load_int(&runtime->initialized);
}

static inline void
_PyRuntimeState_SetInitialized(_PyRuntimeState *runtime, int initialized) {
_Py_atomic_store_int_release(&runtime->initialized, initialized);
_Py_atomic_store_int(&runtime->initialized, initialized);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
:c:func:`Py_IsInitialized` no longer returns true until initialization has
fully completed, including import of the :mod:`site` module. The underlying
runtime flags now use atomic operations with acquire/release memory ordering.
runtime flags now use atomic operations.
Loading