1 #include "libthreads.h"
5 /* global "model" object */
9 * Return 1 if found next thread, 0 otherwise
11 static int thread_system_next(void)
15 curr = thread_current();
17 if (curr->get_state() == THREAD_READY) {
18 model->check_current_action();
19 model->scheduler->add_thread(curr);
20 } else if (curr->get_state() == THREAD_RUNNING)
21 /* Stopped while running; i.e., completed */
26 next = model->scheduler->next_thread();
28 next->set_state(THREAD_RUNNING);
29 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
32 return Thread::swap(model->get_system_context(), next);
35 static void thread_wait_finish(void)
40 while (!thread_system_next());
44 * Main system function
49 ucontext_t main_context;
51 model = new ModelChecker();
53 if (getcontext(&main_context))
56 model->set_system_context(&main_context);
59 /* Start user program */
60 model->add_thread(new Thread(&user_thread, &user_main, NULL));
62 /* Wait for all threads to complete */
64 } while (model->next_execution());