forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make CALL_ALLOC_AND_ENTER_INIT thread-safe
- Modify `get_init_for_simple_managed_python_class` to return both init as well as the type version at the time of lookup. - Modify caching logic to verify that the current version of the type matches the version at the time of lookup. This prevents potentially caching a stale value if we race with an update to __init__. - Only cache __init__ functions that are deferred in free-threaded builds. This ensures that the borrowed reference to __init__ that is stored in the cache is valid if the type version guard in _CHECK_AND_ALLOCATE_OBJECT passes: 1. The type version is cleared before the reference in the MRO to __init__ is destroyed. 2. If the reference in (1) was the last reference then the __init__ method will be queued for deletion the next time GC runs. 3. GC requires stopping the world, which forces a synchronizes-with operation between all threads. 4. If the GC collects the cached __init__, then type's version will have been updated *and* the update will be visible to all threads, so the guard cannot pass. - There are no escaping calls in between loading from the specialization cache and pushing the frame. This is a requirement for the default build.
- Loading branch information
Showing
4 changed files
with
54 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters