8000 don't fiddle with thread structs that were not initialized yet (#6978) · Mars2018/arangodb@b23ba07 · GitHub
[go: up one dir, main page]

Skip to content

Commit b23ba07

Browse files
authored
don't fiddle with thread structs that were not initialized yet (arangodb#6978)
1 parent db9ec61 commit b23ba07

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/Basics/Thread.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ std::string Thread::stringify(ThreadState state) {
158158

159159
Thread::Thread(std::string const& name, bool deleteOnExit)
160160
: _deleteOnExit(deleteOnExit),
161+
_threadStructInitialized(false),
161162
_name(name),
162163
_thread(),
163164
_threadNumber(0),
@@ -181,12 +182,14 @@ Thread::~Thread() {
181182
<< "delete(" << _name << "), state: " << stringify(state);
182183

183184
if (state == ThreadState::STOPPED) {
184-
if (TRI_IsSelfThread(&_thread)) {
185-
// we must ignore any errors here, but TRI_DetachThread will log them
186-
TRI_DetachThread(&_thread);
187-
} else {
188-
// we must ignore any errors here, but TRI_JoinThread will log them
189-
TRI_JoinThread(&_thread);
185+
if (_threadStructInitialized) {
186+
if (TRI_IsSelfThread(&_thread)) {
187+
// we must ignore any errors here, but TRI_DetachThread will log them
188+
TRI_DetachThread(&_thread);
189+
} else {
190+
// we must ignore any errors here, but TRI_JoinThread will log them
191+
TRI_JoinThread(&_thread);
192+
}
190193
}
191194

192195
_state.store(ThreadState::DETACHED);
@@ -320,6 +323,9 @@ bool Thread::start(ConditionVariable* finishedCondition) {
320323
return false;
321324
}
322325

326+
TRI_ASSERT(!_threadStructInitialized);
327+
memset(&_thread, 0, sizeof(thread_t));
328+
323329
bool ok =
324330
TRI_StartThread(&_thread, &_threadId, _name.c_str(), &startThread, this);
325331

@@ -333,6 +339,8 @@ bool Thread::start(ConditionVariable* finishedCondition) {
333339
cleanupMe();
334340
}
335341

342+
_threadStructInitialized = true;
343+
336344
return ok;
337345
}
338346

lib/Basics/Thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class Thread {
212212

213213
private:
214214
bool const _deleteOnExit;
215+
bool _threadStructInitialized;
215216

216217
// name of the thread
217218
std::string const _name;

0 commit comments

Comments
 (0)
0