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, if
18 * @return Returns 0 (success) if there is another step and non-zero otherwise.
20 static int thread_system_next(void) {
23 curr = thread_current();
25 if (curr->get_state() == THREAD_READY) {
26 model->check_current_action();
27 model->scheduler->add_thread(curr);
28 } else if (curr->get_state() == THREAD_RUNNING) {
29 /* Stopped while running; i.e., completed */
35 next = model->scheduler->next_thread();
37 /* Infeasible -> don't take any more steps */
38 if (!model->isfeasible())
42 next->set_state(THREAD_RUNNING);
43 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
45 /* next == NULL -> don't take any more steps */
48 /* Return non-zero only if swap fails with an error */
49 return Thread::swap(model->get_system_context(), next);
52 /** The thread_wait_finish method runs the current execution until we
53 * have no more steps to take.
55 static void thread_wait_finish(void) {
58 while (!thread_system_next());
61 static void parse_options(struct model_params *params, int argc, char **argv) {
67 /** The real_main function contains the main model checking loop. */
68 static void real_main() {
70 ucontext_t main_context;
71 struct model_params params;
73 parse_options(¶ms, main_argc, main_argv);
75 //Initialize race detector
78 //Create the singleton SnapshotStack object
79 snapshotObject = new SnapshotStack();
81 model = new ModelChecker(params);
83 if (getcontext(&main_context))
86 model->set_system_context(&main_context);
88 snapshotObject->snapshotStep(0);
90 /* Start user program */
91 model->add_thread(new Thread(&user_thread, (void (*)(void *)) &user_main, NULL));
93 /* Wait for all threads to complete */
95 } while (model->next_execution());
103 * Main function. Just initializes snapshotting library and the
104 * snapshotting library calls the real_main function.
106 int main(int argc, char ** argv) {
110 /* Let's jump in quickly and start running stuff */
111 initSnapShotLibrary(10000, 1024, 1024, 1000, &real_main);