-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Add HEAD_ISLOCKED to wrap GIL check #125908
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
Comments
Eh, this seems like the wrong approach. I would be more comfortable with either making the mutex recursive, rather than implicitly releasing it for cases like this. |
Maybe we can wait for a solution to the problem. |
The solution to that problem is to make it a recursive mutex :) |
I don't think we want to use a recursive mutex for the linked list of thread states (or interpreter states). That pattern is still prone to lock ordering deadlocks with other threads because (I also think that releasing the mutex implicitly is not the right strategy either) |
Is it necessary to introduce the macro I mentioned for safely unlocking HEAD_LOCK? It can safely release the lock and eliminate errors caused by releasing when the context is not held. |
I'll defer to Sam, as he knows much more about locking than I do, but I'm -1 on this, because it's generally a bad idea to implicitly release locks. |
In fact, the current change solves the competition, but it does not solve the problem of probability deadlock. |
Feature or enhancement
Proposal:
This issue is extracted from #125561.
When interpretation_clear is changed, the
PyThreadState_Clear
function needs to be called whenHEAD_LOCK
is not held, but in fact we cannot be sure, but it existed before the change. In fact, PR solves the competition, but does not eliminate the risk of deadlock, so I give the following solution.For
PyThreadState_Clear
, I want to add aHEAD_ISLOCKED
macro to wrapPyMutex_IsLocked
. This allows a check to be made when UNLOCK is called. Otherwise, if HEAD_LOCK is not called in the context, an is unlock error will occur when HEAD_UNLOCK is called. But in fact, we cannot be sure whether HEAD_LOCK is called in the context, and HEAD_IS_LOCK can be used to check it.changed
The above code will show no locked when the context does not hold HEAD_LOCK, but this is not certain. So I want to add an if statement in front to unlock it when holding HEAD_LOCK. Ensure that there is no deadlock when calling
PyThreadState_Clear
.Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: