1 #include "libthreads.h"
5 /* global "model" object */
9 * Return 1 if found next thread, 0 otherwise
15 static int thread_system_next(void)
19 curr = thread_current();
21 if (curr->get_state() == THREAD_READY) {
22 model->check_current_action();
23 model->scheduler->add_thread(curr);
24 } else if (curr->get_state() == THREAD_RUNNING)
25 /* Stopped while running; i.e., completed */
30 next = model->scheduler->next_thread();
32 next->set_state(THREAD_RUNNING);
33 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
36 return Thread::swap(model->get_system_context(), next);
39 static void thread_wait_finish(void)
44 while (!thread_system_next());
48 * Main system function
53 ucontext_t main_context;
55 model = new ModelChecker();
57 if (getcontext(&main_context))
60 model->set_system_context(&main_context);
63 /* Start user program */
64 model->add_thread(new Thread(&user_thread, &user_main, NULL));
66 /* Wait for all threads to complete */
68 } while (model->next_execution());