The thread that owns a
mutex can specify the same
mutex in repeated wait function calls without blocking its execution. Typically, you would not wait repeatedly for the same
mutex, but this mechanism prevents a thread from deadlocking itself while waiting for a
mutex that it already owns. However, to release its ownership, the thread must call ReleaseMutex once for each time that the
mutex satisfied a wait.
Two or more processes can call CreateMutex to create the same named
mutex. The first process actually creates the
mutex, and subsequent processes with sufficient
access rights simply open a
handle to the existing
mutex. This enables multiple processes to get handles of the same
mutex, while relieving the user of the responsibility of ensuring that the creating process is started first. When using this technique, you should set the bInitialOwner flag to FALSE; otherwise, it can be difficult to be certain which process has initial ownership.