3 #include "libthreads.h"
8 /* global "model" object */
12 * Return 1 if found next thread, 0 otherwise
14 static int thread_system_next(void)
18 curr = thread_current();
20 if (curr->get_state() == THREAD_READY) {
21 model->check_current_action();
22 model->scheduler->add_thread(curr);
23 } else if (curr->get_state() == THREAD_RUNNING)
24 /* Stopped while running; i.e., completed */
29 next = model->scheduler->next_thread();
31 next->set_state(THREAD_RUNNING);
32 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
35 return Thread::swap(model->get_system_context(), next);
38 static void thread_wait_finish(void)
43 while (!thread_system_next());
47 * Main system function
52 ucontext_t main_context;
54 model = new ModelChecker();
56 if (getcontext(&main_context))
59 model->set_system_context(&main_context);
62 /* Start user program */
63 model->add_thread(new Thread(&user_thread, &user_main, NULL));
65 /* Wait for all threads to complete */
67 } while (model->next_execution());