1
0
Fork 0

don't fiddle with thread structs that were not initialized yet (#6979)

This commit is contained in:
Jan 2018-10-22 16:49:13 +02:00 committed by GitHub
parent 4e7f56a532
commit 29383d1082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -138,6 +138,7 @@ std::string Thread::stringify(ThreadState state) {
/// @brief constructs a thread
Thread::Thread(std::string const& name, bool deleteOnExit)
: _deleteOnExit(deleteOnExit),
_threadStructInitialized(false),
_name(name),
_thread(),
_threadNumber(0),
@ -155,12 +156,14 @@ Thread::~Thread() {
<< "delete(" << _name << "), state: " << stringify(state);
if (state == ThreadState::STOPPED) {
if (TRI_IsSelfThread(&_thread)) {
// we must ignore any errors here, but TRI_DetachThread will log them
TRI_DetachThread(&_thread);
} else {
// we must ignore any errors here, but TRI_JoinThread will log them
TRI_JoinThread(&_thread);
if (_threadStructInitialized) {
if (TRI_IsSelfThread(&_thread)) {
// we must ignore any errors here, but TRI_DetachThread will log them
TRI_DetachThread(&_thread);
} else {
// we must ignore any errors here, but TRI_JoinThread will log them
TRI_JoinThread(&_thread);
}
}
_state.store(ThreadState::DETACHED);
@ -282,6 +285,9 @@ bool Thread::start(ConditionVariable* finishedCondition) {
return false;
}
TRI_ASSERT(!_threadStructInitialized);
memset(&_thread, 0, sizeof(thread_t));
bool ok =
TRI_StartThread(&_thread, &_threadId, _name.c_str(), &startThread, this);
@ -295,6 +301,8 @@ bool Thread::start(ConditionVariable* finishedCondition) {
cleanupMe();
}
_threadStructInitialized = true;
return ok;
}

View File

@ -151,6 +151,7 @@ class Thread {
private:
bool const _deleteOnExit;
bool _threadStructInitialized;
// name of the thread
std::string const _name;