1 #include "libthreads.h"
5 /* global "model" object */
7 #include "snapshot-interface.h"
10 * Return 1 if found next thread, 0 otherwise
12 static int thread_system_next(void) {
15 curr = thread_current();
17 if (curr->get_state() == THREAD_READY) {
18 model->check_current_action();
19 model->scheduler->add_thread(curr);
20 } else if (curr->get_state() == THREAD_RUNNING)
21 /* Stopped while running; i.e., completed */
26 next = model->scheduler->next_thread();
28 next->set_state(THREAD_RUNNING);
29 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
32 return Thread::swap(model->get_system_context(), next);
35 static void thread_wait_finish(void) {
38 while (!thread_system_next());
43 ucontext_t main_context;
45 //Create the singleton SnapshotStack object
46 snapshotObject = new SnapshotStack();
48 model = new ModelChecker();
50 if (getcontext(&main_context))
53 model->set_system_context(&main_context);
55 snapshotObject->snapshotStep(0);
58 /* Start user program */
59 model->add_thread(new Thread(&user_thread, (void (*)(void *)) &user_main, NULL));
61 /* Wait for all threads to complete */
63 } while (model->next_execution());
74 * Main system function
76 int main(int numargs, char ** args) {
77 /* Stash this stuff in case someone wants it eventually */
81 /* Let's jump in quickly and start running stuff */
82 initSnapShotLibrary(10000, 1024, 1024, 1000, &real_main);