We don't need to support the case that Thread::complete() is called
multiple times. We should instead ensure (ASSERT()) that it is only
called when the Thread is not already completed (and cleaned up).
/** Terminate a thread and free its stack. */
void Thread::complete()
{
- if (!is_complete()) {
- DEBUG("completed thread %d\n", id_to_int(get_id()));
- state = THREAD_COMPLETED;
- if (stack)
- stack_free(stack);
- }
+ ASSERT(!is_complete());
+ DEBUG("completed thread %d\n", id_to_int(get_id()));
+ state = THREAD_COMPLETED;
+ if (stack)
+ stack_free(stack);
}
/**
/** Destructor */
Thread::~Thread()
{
- complete();
+ if (!is_complete())
+ complete();
model->remove_thread(this);
}