- 論壇徽章:
- 5
|
吧mutex的屬性從PTHREAD_MUTEX_NORMAL改成PTHREAD_MUTEX_ERRORCHECK試試,然后做個判斷檢查,一旦已經(jīng)鎖住返回err,就打印到Log里面去。PTHREAD_MUTEX_NORMAL當當前線程已經(jīng)有鎖了再鎖一次應(yīng)該就會被鎖住的,而PTHREAD_MUTEX_ERRORCHECK會直接返回error。
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. |
|