wpiutil: SafeThread: Ensure thread is released in destructor (#1358)

The thread must be released with either a detach or a join, otherwise
std::terminate is called.
This commit is contained in:
Peter Johnson
2018-10-06 18:07:56 -07:00
committed by GitHub
parent 613d5eda0d
commit 0a937bb5b9

View File

@@ -40,9 +40,9 @@ void detail::SafeThreadOwnerBase::Stop() {
if (auto thr = m_thread.lock()) {
thr->m_active = false;
thr->m_cond.notify_all();
m_stdThread.detach();
m_thread.reset();
}
if (m_stdThread.joinable()) m_stdThread.detach();
}
void detail::SafeThreadOwnerBase::Join() {
@@ -54,6 +54,8 @@ void detail::SafeThreadOwnerBase::Join() {
thr->m_active = false;
thr->m_cond.notify_all();
stdThread.join();
} else if (m_stdThread.joinable()) {
m_stdThread.detach();
}
}