mirror of https://gitee.com/bigwinds/arangodb
don't fiddle with thread structs that were not initialized yet (#6979)
This commit is contained in:
parent
4e7f56a532
commit
29383d1082
|
@ -138,6 +138,7 @@ std::string Thread::stringify(ThreadState state) {
|
||||||
/// @brief constructs a thread
|
/// @brief constructs a thread
|
||||||
Thread::Thread(std::string const& name, bool deleteOnExit)
|
Thread::Thread(std::string const& name, bool deleteOnExit)
|
||||||
: _deleteOnExit(deleteOnExit),
|
: _deleteOnExit(deleteOnExit),
|
||||||
|
_threadStructInitialized(false),
|
||||||
_name(name),
|
_name(name),
|
||||||
_thread(),
|
_thread(),
|
||||||
_threadNumber(0),
|
_threadNumber(0),
|
||||||
|
@ -155,12 +156,14 @@ Thread::~Thread() {
|
||||||
<< "delete(" << _name << "), state: " << stringify(state);
|
<< "delete(" << _name << "), state: " << stringify(state);
|
||||||
|
|
||||||
if (state == ThreadState::STOPPED) {
|
if (state == ThreadState::STOPPED) {
|
||||||
if (TRI_IsSelfThread(&_thread)) {
|
if (_threadStructInitialized) {
|
||||||
// we must ignore any errors here, but TRI_DetachThread will log them
|
if (TRI_IsSelfThread(&_thread)) {
|
||||||
TRI_DetachThread(&_thread);
|
// we must ignore any errors here, but TRI_DetachThread will log them
|
||||||
} else {
|
TRI_DetachThread(&_thread);
|
||||||
// we must ignore any errors here, but TRI_JoinThread will log them
|
} else {
|
||||||
TRI_JoinThread(&_thread);
|
// we must ignore any errors here, but TRI_JoinThread will log them
|
||||||
|
TRI_JoinThread(&_thread);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_state.store(ThreadState::DETACHED);
|
_state.store(ThreadState::DETACHED);
|
||||||
|
@ -282,6 +285,9 @@ bool Thread::start(ConditionVariable* finishedCondition) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRI_ASSERT(!_threadStructInitialized);
|
||||||
|
memset(&_thread, 0, sizeof(thread_t));
|
||||||
|
|
||||||
bool ok =
|
bool ok =
|
||||||
TRI_StartThread(&_thread, &_threadId, _name.c_str(), &startThread, this);
|
TRI_StartThread(&_thread, &_threadId, _name.c_str(), &startThread, this);
|
||||||
|
|
||||||
|
@ -295,6 +301,8 @@ bool Thread::start(ConditionVariable* finishedCondition) {
|
||||||
cleanupMe();
|
cleanupMe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_threadStructInitialized = true;
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,7 @@ class Thread {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool const _deleteOnExit;
|
bool const _deleteOnExit;
|
||||||
|
bool _threadStructInitialized;
|
||||||
|
|
||||||
// name of the thread
|
// name of the thread
|
||||||
std::string const _name;
|
std::string const _name;
|
||||||
|
|
Loading…
Reference in New Issue