Uh oh!
There was an error while loading. Please reload this page.
gh-154928: Fix data race on the recursion count of threading.RLock - #155381
gh-154928: Fix data race on the recursion count of threading.RLock#155381deadlovelll wants to merge 1 commit into
Conversation
I want to give a little disclaimer about my solution, maybe it would answer the possible questions during the review. At the first attempt i tried to change type of _PyRecursiveMutex's where it shoots into the knee: import_threadr=_thread.RLock()
r._acquire_restore((0, _thread.get_ident()))
r.release()When we execute this code with Assertionfailed: (m->level==0), function_PyRecursiveMutex_TryUnlock,
filelock.c, line466.Because in Then in int_PyRecursiveMutex_TryUnlock(_PyRecursiveMutex*m)
{
PyThread_ident_tthread=PyThread_get_thread_ident_ex();
if (!recursive_mutex_is_owned_by(m, thread)) {
return-1;
}
if (m->level>0) {
FT_ATOMIC_STORE_SIZE_RELAXED(m->level, m->level-1);
return0;
}
assert(m->level==0);
_Py_atomic_store_ullong_relaxed(&m->thread, 0);
PyMutex_Unlock(&m->mutex);
return0;
}So in this fix I preferred to be conservative and keep the current semantics, despite the bigger diff. My first version - deadlovelll@c2f316e |
Fix data race on the recursion count of threading.RLock
For more details see gh-154928