2 * @brief Entry point for the model checker.
5 #include "libthreads.h"
11 /* global "model" object */
13 #include "snapshot-interface.h"
16 * The thread_system_next function takes the next step in the execution.
17 * @return Returns the 1 if there is another step and 0 otherwise.
19 static int thread_system_next(void) {
22 curr = thread_current();
24 if (curr->get_state() == THREAD_READY) {
25 model->check_current_action();
26 model->scheduler->add_thread(curr);
27 } else if (curr->get_state() == THREAD_RUNNING)
28 /* Stopped while running; i.e., completed */
33 next = model->scheduler->next_thread();
34 if (!model->isfeasible())
37 next->set_state(THREAD_RUNNING);
38 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
41 return Thread::swap(model->get_system_context(), next);
44 /** The thread_wait_finish method runs the current execution until we
45 * have no more steps to take.
47 static void thread_wait_finish(void) {
50 while (!thread_system_next());
54 /** The real_main function contains the main model checking loop. */
55 static void real_main() {
57 ucontext_t main_context;
59 //Initialize race detector
62 //Create the singleton SnapshotStack object
63 snapshotObject = new SnapshotStack();
65 model = new ModelChecker();
67 if (getcontext(&main_context))
70 model->set_system_context(&main_context);
72 snapshotObject->snapshotStep(0);
74 /* Start user program */
75 model->add_thread(new Thread(&user_thread, (void (*)(void *)) &user_main, NULL));
77 /* Wait for all threads to complete */
79 } while (model->next_execution());
90 * Main function. Just initializes snapshotting library and the
91 * snapshotting library calls the real_main function.
93 int main(int numargs, char ** args) {
94 /* Stash this stuff in case someone wants it eventually */
98 /* Let's jump in quickly and start running stuff */
99 initSnapShotLibrary(10000, 1024, 1024, 1000, &real_main);