Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed data race in all_type_info in free-threading mode #5419

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Oct 24, 2024

  1. Fix data race all_type_info_populate in free-threading mode

    Description:
    - fixed data race all_type_info_populate in free-threading mode
    - added test
    
    For example, we have 2 threads entering `all_type_info`.
    Both enter `all_type_info_get_cache`` function and
    there is a first one which inserts a tuple (type, empty_vector) to the map
    and second is waiting. Inserting thread gets the (iter_to_key, True) and non-inserting thread
    after waiting gets (iter_to_key, False).
    Inserting thread than will add a weakref and will then call into `all_type_info_populate`.
    However, non-inserting thread is not entering `if (ins.second) {` clause and
    returns `ins.first->second;`` which is just empty_vector.
    Finally, non-inserting thread is failing the check in `allocate_layout`:
    ```c++
    if (n_types == 0) {
        pybind11_fail(
            "instance allocation failed: new instance has no pybind11-registered base types");
    }
    ```
    vfdev-5 committed Oct 24, 2024
    Configuration menu
    Copy the full SHA
    6ab21db View commit details
    Browse the repository at this point in the history
  2. style: pre-commit fixes

    pre-commit-ci[bot] authored and vfdev-5 committed Oct 24, 2024
    Configuration menu
    Copy the full SHA
    adbbbba View commit details
    Browse the repository at this point in the history