- 论坛徽章:
- 5
|
吧mutex的属性从PTHREAD_MUTEX_NORMAL改成PTHREAD_MUTEX_ERRORCHECK试试,然后做个判断检查,一旦已经锁住返回err,就打印到Log里面去。PTHREAD_MUTEX_NORMAL当当前线程已经有锁了再锁一次应该就会被锁住的,而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. |
|