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);
}
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();
}
#include <ucontext.h>
+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);