1 #include "libthreads.h"
5 /* global "model" object */
8 #include "snapshot-interface.h"
11 * Return 1 if found next thread, 0 otherwise
17 static int thread_system_next(void) {
20 curr = thread_current();
22 if (curr->get_state() == THREAD_READY) {
23 model->check_current_action();
24 model->scheduler->add_thread(curr);
25 } else if (curr->get_state() == THREAD_RUNNING)
26 /* Stopped while running; i.e., completed */
31 next = model->scheduler->next_thread();
33 next->set_state(THREAD_RUNNING);
34 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
37 return Thread::swap(model->get_system_context(), next);
40 static void thread_wait_finish(void) {
43 while (!thread_system_next());
48 ucontext_t main_context;
50 //Create the singleton snapshotStack object
51 snapshotObject = new snapshotStack();
53 model = new ModelChecker();
55 if (getcontext(&main_context))
58 model->set_system_context(&main_context);
61 /* Start user program */
62 model->add_thread(new Thread(&user_thread, &user_main, NULL));
64 /* Wait for all threads to complete */
66 } while (model->next_execution());
77 * Main system function
79 int main(int numargs, char ** args) {
80 /* Stash this stuff in case someone wants it eventually */
84 /* Let's jump in quickly and start running stuff */
85 initSnapShotLibrary(10000 /*int numbackingpages*/, 1024 /*unsigned int numsnapshots*/, 1024 /*unsigned int nummemoryregions*/ , 1000 /*int numheappages*/, &real_main /*MyFuncPtr entryPoint*/);