From: Brian Norris Date: Tue, 13 Mar 2012 03:38:18 +0000 (-0700) Subject: libthreads: add THREAD_* states X-Git-Tag: pldi2013~591 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9d5424201af87d2824eb9411f1afa42e82e2f602;p=model-checker.git libthreads: add THREAD_* states --- diff --git a/libthreads.c b/libthreads.c index 8d76bf1..892d784 100644 --- a/libthreads.c +++ b/libthreads.c @@ -70,7 +70,7 @@ int thread_yield(void) static void thread_dispose(struct thread *t) { DEBUG("completed thread %d\n", thread_current()->index); - t->completed = 1; + t->state = THREAD_COMPLETED; stack_free(t->stack); } @@ -106,13 +106,15 @@ int thread_create(struct thread *t, void (*start_routine), void *arg) if (ret) return ret; + t->state = THREAD_CREATED; + model->scheduler->add_thread(t); return 0; } void thread_join(struct thread *t) { - while (!t->completed) + while (t->state != THREAD_COMPLETED) thread_yield(); } diff --git a/libthreads.h b/libthreads.h index c0eb7d7..bf7acae 100644 --- a/libthreads.h +++ b/libthreads.h @@ -3,13 +3,20 @@ #include +typedef enum thread_state { + THREAD_CREATED, + THREAD_RUNNING, + THREAD_READY, + THREAD_COMPLETED +} thread_state; + struct thread { void (*start_routine); void *arg; ucontext_t context; void *stack; int index; - int completed; + thread_state state; }; int thread_create(struct thread *t, void (*start_routine), void *arg);