X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=model.cc;h=54f01855adb2987e467e5556338edde4e1204a70;hb=e8b52d444be1e3fd84ca8d0492356cafb76d71ac;hp=136898e913808803972f63d5b7bcd67b1b945a5e;hpb=8127a0c80483af6e238f8cf2b6910a1e7da22416;p=c11tester.git diff --git a/model.cc b/model.cc index 136898e9..54f01855 100644 --- a/model.cc +++ b/model.cc @@ -428,8 +428,18 @@ void ModelChecker::finishRunExecution(ucontext_t *old) void ModelChecker::consumeAction() { ModelAction *curr = chosen_thread->get_pending(); - chosen_thread->set_pending(NULL); - chosen_thread = execution->take_step(curr); + Thread * th = thread_current(); + if (curr->get_type() == THREAD_FINISH && th != NULL) { + // Thread finish must be consumed in the master context + scheduler->set_current_thread(NULL); + if (Thread::swap(th, &system_context) < 0) { + perror("swap threads"); + exit(EXIT_FAILURE); + } + } else { + chosen_thread->set_pending(NULL); + chosen_thread = execution->take_step(curr); + } } void ModelChecker::chooseThread(ModelAction *act, Thread *thr) @@ -477,12 +487,10 @@ uint64_t ModelChecker::switch_thread(ModelAction *act) if (old->is_waiting_on(old)) assert_bug("Deadlock detected (thread %u)", curr_thread_num); - ModelAction *act2 = old->get_pending(); - - if (act2 && execution->is_enabled(old) && !execution->check_action_enabled(act2)) { + if (act && execution->is_enabled(old) && !execution->check_action_enabled(act)) { scheduler->sleep(old); } -// chooseThread(act2, old); +// chooseThread(act, old); curr_thread_num++; Thread* next = getNextThread();