[core] fix tsbpd() may deadlock with processCtrlShutdown() #2740
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I experienced a deadlock issue, the
CRcvQueue::worker
thread was blocked inprocessCtrlShutdown()->releaseSynch()->pthread_join()
forever:While the corresponding
tsbpd
thread of@94643394
was blocked inwait()
forever:The only reason I can find is that the
srt/srtcore/core.cpp
Line 7654 in 3cefede
happened while the
tsbpd
thread was undersrt/srtcore/core.cpp
Line 5436 in 3cefede
The order was
TsbPd: unlock(m_RecvLock)
->RcvQ: lock_notify(m_RcvTsbPdCond, m_RecvLock); m_RcvTsbPdThread.join()
->TsbPd: lock(m_RecvLock); tsbpd_cc.wait()
The proposed solution is simple. We just need to check
m_bClosing
again after re-lockingm_RecvLock
:m_bClosing = true
happens before this check, thetsbpd
thread will exit after this check.m_bClosing = true
happens after this check, the followinglock_notify(m_RcvTsbPdCond, m_RecvLock)
will happen aftertsbpd_cc.wait()
(because of them_RecvLock
), so thetsbpd
thread will be woken up and cleared.