@@ -158,6 +158,7 @@ std::string Thread::stringify(ThreadState state) {
158
158
159
159
Thread::Thread (std::string const & name, bool deleteOnExit)
160
160
: _deleteOnExit(deleteOnExit),
161
+ _threadStructInitialized(false ),
161
162
_name(name),
162
163
_thread(),
163
164
_threadNumber(0 ),
@@ -181,12 +182,14 @@ Thread::~Thread() {
181
182
<< " delete(" << _name << " ), state: " << stringify (state);
182
183
183
184
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
+ }
190
193
}
191
194
192
195
_state.store (ThreadState::DETACHED);
@@ -320,6 +323,9 @@ bool Thread::start(ConditionVariable* finishedCondition) {
320
323
return false ;
321
324
}
322
325
326
+ TRI_ASSERT (!_threadStructInitialized);
327
+ memset (&_thread, 0 , sizeof (thread_t ));
328
+
323
329
bool ok =
324
330
TRI_StartThread (&_thread, &_threadId, _name.c_str (), &startThread, this );
325
331
@@ -333,6 +339,8 @@ bool Thread::start(ConditionVariable* finishedCondition) {
333
339
cleanupMe ();
334
340
}
335
341
342
+ _threadStructInitialized = true ;
343
+
336
344
return ok;
337
345
}
338
346
0 commit comments