未知的行为说明具体行为是由实现方决定,POSIX规范不做统一定义。
但是你用man命名查询函数的时候,一般都会告诉你产生什么行为。
The pthread_mutex_unlock() function shall release the mutex object referenced by mutex. The manner
in which a mutex is released is dependent upon the mutex’s type attribute.
我的man里面显示解锁一个已经释放的锁产生的行为与mutex的type属性有关,
那你再查属性。
If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection shall not be provided. Attempting to
relock the mutex causes deadlock. If a thread attempts to unlock a mutex that it has not locked or a
mutex which is unlocked, undefined behavior results.
If the mutex type is PTHREAD_MUTEX_ERRORCHECK, then error checking shall be provided. If a thread
attempts to relock a mutex that it has already locked, an error shall be returned. If a thread
attempts to unlock a mutex that it has not locked or a mutex which is unlocked, an error shall be
returned.
If the mutex type is PTHREAD_MUTEX_RECURSIVE, then the mutex shall maintain the concept of a lock
count. When a thread successfully acquires a mutex for the first time, the lock count shall be set to
one. Every time a thread relocks this mutex, the lock count shall be incremented by one. Each time
the thread unlocks the mutex, the lock count shall be decremented by one. When the lock count reaches
zero, the mutex shall become available for other threads to acquire. If a thread attempts to unlock a
mutex that it has not locked or a mutex which is unlocked, an error shall be returned.
If the mutex type is PTHREAD_MUTEX_DEFAULT, attempting to recursively lock the mutex results in unde-
fined behavior. Attempting to unlock the mutex if it was not locked by the calling thread results in
undefined behavior. Attempting to unlock the mutex if it is not locked results in undefined behavior.