X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=threads.cc;h=6adc053ae2dbfc58a00bbbb2f0e6a7c2e79a7b4c;hb=fbacb5f41ada96e7b539ccc41deccb1a7e1a1ba8;hp=6b4e2c740ab50b7b55f624b7bda05a4c9ad72678;hpb=84d0cd2f078f4cb15c318a0fef2515feab570375;p=model-checker.git diff --git a/threads.cc b/threads.cc index 6b4e2c7..6adc053 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); } /** @@ -162,14 +161,15 @@ Thread::Thread(thrd_t *t, void (*func)(void *), void *a) : model_print("Error in create_context\n"); id = model->get_next_id(); - *user_thread = id; + user_thread->priv = this; parent = thread_current(); } /** Destructor */ Thread::~Thread() { - complete(); + if (!is_complete()) + complete(); model->remove_thread(this); } @@ -178,3 +178,13 @@ thread_id_t Thread::get_id() const { return id; } + +/** + * Set a thread's THREAD_* state (@see thread_state) + * @param s The state to enter + */ +void Thread::set_state(thread_state s) +{ + ASSERT(s == THREAD_COMPLETED || state != THREAD_COMPLETED); + state = s; +}