atomics have been used for threads stop

This commit is contained in:
brain5lug 2017-10-01 00:46:49 +03:00
parent 8c09a7429c
commit dfa1482ab2
15 changed files with 259 additions and 212 deletions

View file

@ -445,19 +445,25 @@ namespace tunnel
void Tunnels::Start ()
{
m_IsRunning = true;
m_Thread = new std::thread (std::bind (&Tunnels::Run, this));
if (!m_IsRunning.load())
{
m_IsRunning.store(true);
m_Thread = new std::thread (std::bind (&Tunnels::Run, this));
}
}
void Tunnels::Stop ()
{
m_IsRunning = false;
m_Queue.WakeUp ();
if (m_Thread)
if (m_IsRunning.load())
{
m_Thread->join ();
delete m_Thread;
m_Thread = 0;
m_IsRunning.store(false);
m_Queue.WakeUp ();
if (m_Thread)
{
m_Thread->join ();
delete m_Thread;
m_Thread = 0;
}
}
}
@ -466,7 +472,7 @@ namespace tunnel
std::this_thread::sleep_for (std::chrono::seconds(1)); // wait for other parts are ready
uint64_t lastTs = 0;
while (m_IsRunning)
while (m_IsRunning.load(std::memory_order_acquire))
{
try
{