Closed vincentyanzhao closed 2 years ago
Timer lock may cause deadlock
Logging this api has an deadlock; startLock is inited normal mutex, so if you want relock in timerQueueExecutor, it will go wrong,but demo master is is ok , I'm confused!!
STATUS timerQueueCreateInternal(UINT32 maxTimers, PTimerQueue* ppTimerQueue) { pTimerQueue->startLock = MUTEX_CREATE(FALSE); ..... // Block threads start MUTEX_LOCK(pTimerQueue->startLock); locked = TRUE;
// Create the executor thread CHK_STATUS(THREAD_CREATE(&threadId, timerQueueExecutor, (PVOID) pTimerQueue)); CHK_STATUS(THREAD_DETACH(threadId)); pTimerQueue->executorTid = threadId; while (!ATOMIC_LOAD_BOOL(&pTimerQueue->started)) { CHK_STATUS(CVAR_WAIT(pTimerQueue->startCvar, pTimerQueue->startLock, INFINITE_TIME_VALUE)); } MUTEX_UNLOCK(pTimerQueue->startLock); locked = FALSE;
.......
}
Awaiting for CVAR is "unlocking" the lock
Timer lock may cause deadlock
Logging this api has an deadlock; startLock is inited normal mutex, so if you want relock in timerQueueExecutor, it will go wrong,but demo master is is ok , I'm confused!!
STATUS timerQueueCreateInternal(UINT32 maxTimers, PTimerQueue* ppTimerQueue) { pTimerQueue->startLock = MUTEX_CREATE(FALSE); ..... // Block threads start MUTEX_LOCK(pTimerQueue->startLock); locked = TRUE;
.......
}