1 /* -*- Mode: C; indent-tabs-mode: t -*- */
3 #include "libthreads.h"
7 /* global "model" object */
10 #include "snapshot-interface.h"
13 * Return 1 if found next thread, 0 otherwise
15 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) {
41 while (!thread_system_next());
46 ucontext_t main_context;
48 //Create the singleton snapshotStack object
49 snapshotObject = new snapshotStack();
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, (void (*)(void *)) &user_main, NULL));
62 /* Wait for all threads to complete */
64 } while (model->next_execution());
75 * Main system function
77 int main(int numargs, char ** args) {
78 /* Stash this stuff in case someone wants it eventually */
82 /* Let's jump in quickly and start running stuff */
83 initSnapShotLibrary(10000 /*int numbackingpages*/, 1024 /*unsigned int numsnapshots*/, 1024 /*unsigned int nummemoryregions*/ , 1000 /*int numheappages*/, &real_main /*MyFuncPtr entryPoint*/);