If a thread which had already locked a mutex, tries to lock the mutex again, it will enter into waiting list of that mutex which results in deadlock.
@mehtapaxshal hey, you might be right about the deadlock, but from what I understand the only way it would result in a deadlock is if process 2 was holding a different lock that process 1 needed in order to finish and neither process can force the other to give up a lock. Otherwise I think process 1 could finish and process 2 would run, but maybe I am missing something.
This post is talking a bout "Non Recursive" mutex. From wikipedia(https://en.wikipedia.org/wiki/Reentrant_mutex):
any attempt to perform the "lock" operation on an ordinary mutex (lock) would either fail or block when the mutex is already locked.
Then here comes "Recursive"(Reentrant) mutex, which could be locked multiple times by a thread, also requires same amount of unlock operations.
Therefore, if it is an ordinary mutex(non-reentrant), a thread that locks it more than once will either fail or locked(deadlock, cause the thread is waiting itself to unlock the mutex).
@feng.wen.503 True that! Thats make Non Recursive mutex different from Reentrant mutex.
@JNX Hope you got that! Your understanding is also right but its different scenario. I am here talking about deadlock with single or same thread/process.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.