1 #include "libthreads.h"
5 /* global "model" object */
10 * Return 1 if found next thread, 0 otherwise
16 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) {
42 while (!thread_system_next());
47 ucontext_t main_context;
49 model = new ModelChecker();
51 if (getcontext(&main_context))
54 model->set_system_context(&main_context);
57 /* Start user program */
58 model->add_thread(new Thread(&user_thread, &user_main, NULL));
60 /* Wait for all threads to complete */
62 } while (model->next_execution());
73 * Main system function
75 int main(int numargs, char ** args) {
76 /* Stash this stuff in case someone wants it eventually */
80 /* Let's jump in quickly and start running stuff */
81 initSnapShotLibrary(10000 /*int numbackingpages*/, 1024 /*unsigned int numsnapshots*/, 1024 /*unsigned int nummemoryregions*/ , 1000 /*int numheappages*/, &real_main /*MyFuncPtr entryPoint*/);