eThread *p = (eThread*) ptr;
p->m_alive = 0;
- /* recover state */
- if (!p->m_state.value())
- {
- p->m_state.up();
- ASSERT(p->m_state.value() == 1);
- }
+ /* recover state in case thread was cancelled before calling hasStarted */
+ if (!p->m_started)
+ p->hasStarted();
p->thread_finished();
}
ASSERT(m_state.value() == 1); /* sync postconditions */
ASSERT(!m_alive);
m_state.down();
+ ASSERT(m_state.value() == 0);
m_alive = 1;
+ m_started = 0;
/* start thread. */
pthread_attr_t attr;
int eThread::sync(void)
{
int res;
+ int debug_val_before = m_state.value();
m_state.down(); /* this might block */
res = m_alive;
+ if (m_state.value() != 0)
+ eFatal("eThread::sync: m_state.value() == %d - was %d before", m_state.value(), debug_val_before);
ASSERT(m_state.value() == 0);
m_state.up();
return res; /* 0: thread is guaranteed not to run. 1: state unknown. */
void eThread::hasStarted()
{
ASSERT(!m_state.value());
+ m_started = 1;
m_state.up();
}