Skip to content

Commit 10632f9

Browse files
authored
Merge pull request #28583 from charris/backport-28577
BUG: avoid deadlocks with C++ shared mutex in dispatch cache
2 parents a2bef20 + 37985a2 commit 10632f9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

numpy/_core/src/umath/dispatching.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,9 @@ promote_and_get_info_and_ufuncimpl_with_locking(
912912
npy_bool legacy_promotion_is_possible)
913913
{
914914
std::shared_mutex *mutex = ((std::shared_mutex *)((PyArrayIdentityHash *)ufunc->_dispatch_cache)->mutex);
915+
NPY_BEGIN_ALLOW_THREADS
915916
mutex->lock_shared();
917+
NPY_END_ALLOW_THREADS
916918
PyObject *info = PyArrayIdentityHash_GetItem(
917919
(PyArrayIdentityHash *)ufunc->_dispatch_cache,
918920
(PyObject **)op_dtypes);
@@ -926,7 +928,9 @@ promote_and_get_info_and_ufuncimpl_with_locking(
926928

927929
// cache miss, need to acquire a write lock and recursively calculate the
928930
// correct dispatch resolution
931+
NPY_BEGIN_ALLOW_THREADS
929932
mutex->lock();
933+
NPY_END_ALLOW_THREADS
930934
info = promote_and_get_info_and_ufuncimpl(ufunc,
931935
ops, signature, op_dtypes, legacy_promotion_is_possible);
932936
mutex->unlock();

0 commit comments

Comments
 (0)