From: Brian Norris Date: Tue, 18 Dec 2012 22:08:19 +0000 (-0800) Subject: threads: assert completion is only called once X-Git-Tag: oopsla2013~407 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=09b2cb3cabe0d96f62383a8fdd040e7605a1ffc6;p=model-checker.git threads: assert completion is only called once 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). --- diff --git a/threads.cc b/threads.cc index 87de32f..d170b7a 100644 --- a/threads.cc +++ b/threads.cc @@ -104,12 +104,11 @@ int Thread::swap(ucontext_t *ctxt, Thread *t) /** 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); } /** @@ -169,7 +168,8 @@ Thread::Thread(thrd_t *t, void (*func)(void *), void *a) : /** Destructor */ Thread::~Thread() { - complete(); + if (!is_complete()) + complete(); model->remove_thread(this); }