3 #include "libthreads.h"
8 /* global "model" object */
12 * Return 1 if found next thread, 0 otherwise
18 static int thread_system_next(void)
22 curr = thread_current();
24 if (curr->get_state() == THREAD_READY) {
25 model->check_current_action();
26 model->scheduler->add_thread(curr);
27 } else if (curr->get_state() == THREAD_RUNNING)
28 /* Stopped while running; i.e., completed */
33 next = model->scheduler->next_thread();
35 next->set_state(THREAD_RUNNING);
36 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
39 return Thread::swap(model->get_system_context(), next);
42 static void thread_wait_finish(void)
47 while (!thread_system_next());
51 * Main system function
56 ucontext_t main_context;
58 model = new ModelChecker();
60 if (getcontext(&main_context))
63 model->set_system_context(&main_context);
66 /* Start user program */
67 model->add_thread(new Thread(&user_thread, &user_main, NULL));
69 /* Wait for all threads to complete */
71 } while (model->next_execution());