python / cpython

The Python programming language
https://www.python.org
Other
63.65k stars 30.49k forks source link

[3.13] gh-126914: Store the Preallocated Thread State's Pointer in a PyInterpreterState Field #127114

Open ericsnowcurrently opened 4 days ago

ericsnowcurrently commented 4 days ago

This approach eliminates the originally reported race. It also gets rid of the deadlock reported in gh-96071, so we can remove the workaround added then.

This is mostly a cherry-pick of 1c0a104eca189a932e0b44ca9bef46cce3d0b801 (AKA gh-126989). The difference is we add PyInterpreterState.threads_preallocated at the end of PyInterpreterState, instead of adding PyInterpreterState.threads.preallocated. That avoids ABI disruption.

ericsnowcurrently commented 4 days ago

@Yhg1s, this changes only internal ABI, so we should be fine updating the ABI data file, right?

Yhg1s commented 9 hours ago

Yes, the struct is always allocated by the runtime, and the new field is used only by the runtime, never extension modules, so updating the ABI definition is fine.