Skip to content

BUG: fix stringdtype singleton thread safety #28862

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

Merged
merged 2 commits into from
Apr 29, 2025

Conversation

ngoldbaum
Copy link
Member

Fixes #28813.

Two orthogonal but related fixes.

First, to guard against newly created StringDType instances being shared between threads, we acquire the allocator lock before reading and possibly setting the array_owned flag on a descriptor passed to the descriptor finalization function.

Second, I completely removed the singleton for StringDType. Since StringDType uses per-array descriptors, we're always going to need to create a new descriptor for each array anyway. We probably don't want an array to use a globally shared instance either. The tests pass with no other changes to the codebase besides deleting the code that creates the singleton, so I think it's not needed for anything either.

Not sure if we're going to do another 2.2.x, but I think this is also safe to backport.

@ngoldbaum ngoldbaum added 09 - Backport-Candidate PRs tagged should be backported component: numpy.strings String dtypes and functions 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) labels Apr 29, 2025
@ngoldbaum ngoldbaum added this to the 2.2.6 release milestone Apr 29, 2025
Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM, and I think changing the singleton to array_owned should be safe to backport.

@seberg seberg merged commit 1672b69 into numpy:main Apr 29, 2025
74 checks passed
@charris charris added 09 - Backport-Candidate PRs tagged should be backported and removed 09 - Backport-Candidate PRs tagged should be backported labels Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) component: numpy.strings String dtypes and functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Data race in stringdtype_finalize_descr under free-threading
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy