8000 BUG: avoid deadlocks with C++ shared mutex in dispatch cache by ngoldbaum · Pull Request #28577 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: avoid deadlocks with C++ shared mutex in dispatch cache #28577

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 1 commit into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions numpy/_core/src/umath/dispatching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,9 @@ promote_and_get_info_and_ufuncimpl_with_locking(
npy_bool legacy_promotion_is_possible)
{
std::shared_mutex *mutex = ((std::shared_mutex *)((PyArrayIdentityHash *)ufunc->_dispatch_cache)->mutex);
NPY_BEGIN_ALLOW_THREADS
mutex->lock_shared();
NPY_END_ALLOW_THREADS
PyObject *info = PyArrayIdentityHash_GetItem(
(PyArrayIdentityHash *)ufunc->_dispatch_cache,
(PyObject **)op_dtypes);
Expand All @@ -926,7 +928,9 @@ promote_and_get_info_and_ufuncimpl_with_locking(

// cache miss, need to acquire a write lock and recursively calculate the
// correct dispatch resolution
NPY_BEGIN_ALLOW_THREADS
mutex->lock();
NPY_END_ALLOW_THREADS
info = promote_and_get_info_and_ufuncimpl(ufunc,
ops, signature, op_dtypes, legacy_promotion_is_possible);
mutex->unlock();
Expand Down
Loading
0