Deadlock happens when two threads are waiting for a mutex owned by the other (circular deadlock between multiple threads is also possible). Therefore, we need to check for deadlock only when a thread fails to lock a mutex. At that point, the Thread Manager needs to suspend all threads and take over to perform a cycle check on mutex dependency. Finding such a cycle is easily done by performing a tree traversal of the dependencies, and marking threads and mutexes along the way. Using this method, we can detect deadlock and identify all threads and mutexes involved in the deadlock.