You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
why do we wait 1 second to stop the thread?
if there is any potential race condition, probably 100ms is enough? or could be even shorter.
However, I feel it's an anti-pattern to use sleep to ensure the behavior is correct.
voidPcapLiveDevice::stopCapture()
{
// in blocking mode stop capture isn't relevantif (m_cbOnPacketArrivesBlockingMode != nullptr)
return;
m_StopThread = true;
if (m_CaptureThreadStarted)
{
pcap_breakloop(m_PcapDescriptor);
PCPP_LOG_DEBUG("Stopping capture thread, waiting for it to join...");
m_CaptureThread.join();
m_CaptureThreadStarted = false;
PCPP_LOG_DEBUG("Capture thread stopped for device '" << m_Name << "'");
}
PCPP_LOG_DEBUG("Capture thread stopped for device '" << m_Name << "'");
if (m_StatsThreadStarted)
{
PCPP_LOG_DEBUG("Stopping stats thread, waiting for it to join...");
m_StatsThread.join();
m_StatsThreadStarted = false;
PCPP_LOG_DEBUG("Stats thread stopped for device '" << m_Name << "'");
}
multiPlatformSleep(1);
m_StopThread = false;
}
why do we wait 1 second to stop the thread?
if there is any potential race condition, probably 100ms is enough? or could be even shorter.
However, I feel it's an anti-pattern to use
sleep
to ensure the behavior is correct.cc @clementperon @seladb
The text was updated successfully, but these errors were encountered: