awslabs / amazon-kinesis-video-streams-pic

Apache License 2.0
49 stars 51 forks source link

[QUESTION] Timer lock may cause deadlock #164

Closed vincentyanzhao closed 2 years ago

vincentyanzhao commented 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;

.......

}

MushMal commented 2 years ago

Awaiting for CVAR is "unlocking" the lock