-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: master
Are you sure you want to change the base?
Fixed data race in all_type_info in free-threading mode #5419
Conversation
d98dd4b
to
8beaa20
Compare
7d1a270
to
1a07f3c
Compare
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"); } ```
ef3fb1c
to
6ab21db
Compare
cdc1663
to
adbbbba
Compare
I think we may need a further rework of I'm not entirely sure what the locking strategy should be here. It's possible that all the callers to |
On further thought, I think this approach makes sense. I don't think we need to rework the locking strategy and can address the other data races on I'll write up a summary of the issues. |
@rwgk can you please review this PR? |
Will try tomorrow. @cryos could you please also take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@colesbury could you please formally approve?
Looks good to me, but I'm not a free-threading expert. I'll merge when I see approvals from @colesbury and @cryos.
4336d12
to
22723d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but waiting for approvals from @colesbury and @cryos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this LGTM.
I'll try to put up a follow up PR later this week for the remaining issues described in #5421.
Description
all_type_info
in free-threading modeFor example, we have 2 threads entering
all_type_info
. Both enterall_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 inallocate_layout
:On
master
running this test gives:Suggested changelog entry:
cc @colesbury