When I tried to produce a deadlock in CoreAudio with pthread, I realized that the mutex with NORMAL type locked by one pthread could be unlocked by another pthread. Normally, this behavior should be disallowed. It will result in undefined behaviors. If one pthread could unlock a mutex owned by other thread whenever it wants, then the mutex will be meaningless, unless it’s a expected behavior.
In my case, it’s exactly what I want, because I need to break the deadlock to continue the program. However, in most case, this behavior should be forbidden, so I do some research about what the behaviors of mutexes with different types are.
Here is my conclusion:
The test code can be found on gist here