1 #include "libthreads.h"
5 /* global "model" object */
8 #include "snapshot-interface.h"
11 * Return 1 if found next thread, 0 otherwise
13 static int thread_system_next(void) {
16 curr = thread_current();
18 if (curr->get_state() == THREAD_READY) {
19 model->check_current_action();
20 model->scheduler->add_thread(curr);
21 } else if (curr->get_state() == THREAD_RUNNING)
22 /* Stopped while running; i.e., completed */
27 next = model->scheduler->next_thread();
29 next->set_state(THREAD_RUNNING);
30 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
33 return Thread::swap(model->get_system_context(), next);
36 static void thread_wait_finish(void) {
39 while (!thread_system_next());
44 ucontext_t main_context;
46 //Create the singleton SnapshotStack object
47 snapshotObject = new SnapshotStack();
49 model = new ModelChecker();
51 if (getcontext(&main_context))
54 model->set_system_context(&main_context);
56 snapshotObject->snapshotStep(0);
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, 1024, 1024, 1000, &real_main);