diff --git a/srtcore/core.cpp b/srtcore/core.cpp index b7f2723c2..83ff52f16 100644 --- a/srtcore/core.cpp +++ b/srtcore/core.cpp @@ -9992,12 +9992,13 @@ bool srt::CUDT::overrideSndSeqNo(int32_t seq) int srt::CUDT::checkLazySpawnTsbPdThread() { const bool need_tsbpd = m_bTsbPd || m_bGroupTsbPd; + if (!need_tsbpd) + return 0; - if (need_tsbpd && !m_RcvTsbPdThread.joinable()) + ScopedLock lock(m_RcvTsbPdStartupLock); + if (!m_RcvTsbPdThread.joinable()) { - ScopedLock lock(m_RcvTsbPdStartupLock); - - if (m_bClosing) // Check again to protect join() in CUDT::releaseSync() + if (m_bClosing) // Check m_bClosing to protect join() in CUDT::releaseSync(). return -1; HLOGP(qrlog.Debug, "Spawning Socket TSBPD thread"); diff --git a/srtcore/core.h b/srtcore/core.h index e24bd8152..3935b99d3 100644 --- a/srtcore/core.h +++ b/srtcore/core.h @@ -995,7 +995,7 @@ class CUDT sync::CThread m_RcvTsbPdThread; // Rcv TsbPD Thread handle sync::Condition m_RcvTsbPdCond; // TSBPD signals if reading is ready. Use together with m_RecvLock bool m_bTsbPdNeedsWakeup; // Signal TsbPd thread to wake up on RCV buffer state change. - sync::Mutex m_RcvTsbPdStartupLock; // Protects TSBPD thread creating and joining + sync::Mutex m_RcvTsbPdStartupLock; // Protects TSBPD thread creation and joining. CallbackHolder m_cbAcceptHook; CallbackHolder m_cbConnectHook;