-/**
- * Switch from a model-checker context to a user-thread context. This is the
- * complement of ModelChecker::switch_to_master and must be called from the
- * model-checker context
- *
- * @param thread The user-thread to switch to
- */
-void ModelChecker::switch_from_master(Thread *thread)
+void ModelChecker::startRunExecution(Thread *old) {
+ while (true) {
+ if (params.traceminsize != 0 &&
+ execution->get_curr_seq_num() > checkfree) {
+ checkfree += params.checkthreshold;
+ execution->collectActions();
+ }
+
+ thread_chosen = false;
+ curr_thread_num = 1;
+
+ Thread *thr = getNextThread();
+ if (thr != nullptr) {
+ scheduler->set_current_thread(thr);
+
+ if (Thread::swap(old, thr) < 0) {
+ perror("swap threads");
+ exit(EXIT_FAILURE);
+ }
+ return;
+ }
+
+ if (execution->has_asserted()) {
+ finishRunExecution(old);
+ return;
+ }
+ if (!chosen_thread)
+ chosen_thread = get_next_thread();
+ if (!chosen_thread || chosen_thread->is_model_thread()) {
+ finishRunExecution(old);
+ return;
+ }
+ if (chosen_thread->just_woken_up()) {
+ chosen_thread->set_wakeup_state(false);
+ chosen_thread->set_pending(NULL);
+ chosen_thread = NULL;
+ // Allow this thread to stash the next pending action
+ continue;
+ }
+
+ /* Consume the next action for a Thread */
+ consumeAction();
+
+ if (should_terminate_execution()) {
+ finishRunExecution(old);
+ return;
+ }
+ }
+}
+
+Thread* ModelChecker::getNextThread()