7 #include "snapshot-interface.h"
9 #include "clockvector.h"
10 #include "cyclegraph.h"
13 #define INITIAL_THREAD_ID 0
17 /** @brief Constructor */
18 ModelChecker::ModelChecker(struct model_params params) :
19 /* Initialize default scheduler */
20 scheduler(new Scheduler()),
21 /* First thread created will have id INITIAL_THREAD_ID */
22 next_thread_id(INITIAL_THREAD_ID),
23 used_sequence_numbers(0),
28 nextThread(THREAD_ID_T_NONE),
29 action_trace(new action_list_t()),
30 thread_map(new HashTable<int, Thread *, int>()),
31 obj_map(new HashTable<const void *, action_list_t, uintptr_t, 4>()),
32 obj_thrd_map(new HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 >()),
33 promises(new std::vector<Promise *>()),
34 thrd_last_action(new std::vector<ModelAction *>(1)),
35 node_stack(new NodeStack()),
37 mo_graph(new CycleGraph()),
42 /** @brief Destructor */
43 ModelChecker::~ModelChecker()
45 for (int i = 0; i < get_num_threads(); i++)
46 delete thread_map->get(i);
53 for (unsigned int i = 0; i < promises->size(); i++)
54 delete (*promises)[i];
57 delete thrd_last_action;
64 * Restores user program to initial state and resets all model-checker data
67 void ModelChecker::reset_to_initial_state()
69 DEBUG("+++ Resetting to initial state +++\n");
70 node_stack->reset_execution();
71 current_action = NULL;
72 next_thread_id = INITIAL_THREAD_ID;
73 used_sequence_numbers = 0;
75 next_backtrack = NULL;
76 failed_promise = false;
77 snapshotObject->backTrackBeforeStep(0);
80 /** @returns a thread ID for a new Thread */
81 thread_id_t ModelChecker::get_next_id()
83 return next_thread_id++;
86 /** @returns the number of user threads created during this execution */
87 int ModelChecker::get_num_threads()
89 return next_thread_id;
92 /** @returns a sequence number for a new ModelAction */
93 modelclock_t ModelChecker::get_next_seq_num()
95 return ++used_sequence_numbers;
99 * Performs the "scheduling" for the model-checker. That is, it checks if the
100 * model-checker has selected a "next thread to run" and returns it, if
101 * available. This function should be called from the Scheduler routine, where
102 * the Scheduler falls back to a default scheduling routine if needed.
104 * @return The next thread chosen by the model-checker. If the model-checker
105 * makes no selection, retuns NULL.
107 Thread * ModelChecker::schedule_next_thread()
110 if (nextThread == THREAD_ID_T_NONE)
112 t = thread_map->get(id_to_int(nextThread));
120 * Choose the next thread in the replay sequence.
122 * If the replay sequence has reached the 'diverge' point, returns a thread
123 * from the backtracking set. Otherwise, simply returns the next thread in the
124 * sequence that is being replayed.
126 thread_id_t ModelChecker::get_next_replay_thread()
130 /* Have we completed exploring the preselected path? */
132 return THREAD_ID_T_NONE;
134 /* Else, we are trying to replay an execution */
135 ModelAction *next = node_stack->get_next()->get_action();
137 if (next == diverge) {
138 Node *nextnode = next->get_node();
139 /* Reached divergence point */
140 if (nextnode->increment_promise()) {
141 /* The next node will try to satisfy a different set of promises. */
142 tid = next->get_tid();
143 node_stack->pop_restofstack(2);
144 } else if (nextnode->increment_read_from()) {
145 /* The next node will read from a different value. */
146 tid = next->get_tid();
147 node_stack->pop_restofstack(2);
148 } else if (nextnode->increment_future_value()) {
149 /* The next node will try to read from a different future value. */
150 tid = next->get_tid();
151 node_stack->pop_restofstack(2);
153 /* Make a different thread execute for next step */
154 Node *node = nextnode->get_parent();
155 tid = node->get_next_backtrack();
156 node_stack->pop_restofstack(1);
158 DEBUG("*** Divergence point ***\n");
161 tid = next->get_tid();
163 DEBUG("*** ModelChecker chose next thread = %d ***\n", tid);
168 * Queries the model-checker for more executions to explore and, if one
169 * exists, resets the model-checker state to execute a new execution.
171 * @return If there are more executions to explore, return true. Otherwise,
174 bool ModelChecker::next_execution()
180 if (isfinalfeasible() || DBG_ENABLED())
183 if ((diverge = model->get_next_backtrack()) == NULL)
187 printf("Next execution will diverge at:\n");
191 model->reset_to_initial_state();
195 ModelAction * ModelChecker::get_last_conflict(ModelAction *act)
197 action_type type = act->get_type();
207 /* linear search: from most recent to oldest */
208 action_list_t *list = obj_map->get_safe_ptr(act->get_location());
209 action_list_t::reverse_iterator rit;
210 for (rit = list->rbegin(); rit != list->rend(); rit++) {
211 ModelAction *prev = *rit;
212 if (act->is_synchronizing(prev))
218 void ModelChecker::set_backtracking(ModelAction *act)
222 Thread *t = get_thread(act->get_tid());
224 prev = get_last_conflict(act);
228 node = prev->get_node()->get_parent();
230 while (!node->is_enabled(t))
233 /* Check if this has been explored already */
234 if (node->has_been_explored(t->get_id()))
237 /* Cache the latest backtracking point */
238 if (!next_backtrack || *prev > *next_backtrack)
239 next_backtrack = prev;
241 /* If this is a new backtracking point, mark the tree */
242 if (!node->set_backtrack(t->get_id()))
244 DEBUG("Setting backtrack: conflict = %d, instead tid = %d\n",
245 prev->get_tid(), t->get_id());
253 * Returns last backtracking point. The model checker will explore a different
254 * path for this point in the next execution.
255 * @return The ModelAction at which the next execution should diverge.
257 ModelAction * ModelChecker::get_next_backtrack()
259 ModelAction *next = next_backtrack;
260 next_backtrack = NULL;
264 void ModelChecker::check_current_action(void)
266 ModelAction *curr = this->current_action;
267 bool already_added = false;
268 this->current_action = NULL;
270 DEBUG("trying to push NULL action...\n");
274 if (curr->is_rmwc() || curr->is_rmw()) {
275 ModelAction *tmp = process_rmw(curr);
276 already_added = true;
280 ModelAction *tmp = node_stack->explore_action(curr);
282 /* Discard duplicate ModelAction; use action from NodeStack */
283 /* First restore type and order in case of RMW operation */
285 tmp->copy_typeandorder(curr);
287 /* If we have diverged, we need to reset the clock vector. */
289 tmp->create_cv(get_parent_action(tmp->get_tid()));
295 * Perform one-time actions when pushing new ModelAction onto
298 curr->create_cv(get_parent_action(curr->get_tid()));
299 /* Build may_read_from set */
301 build_reads_from_past(curr);
302 if (curr->is_write())
303 compute_promises(curr);
307 /* Assign 'creation' parent */
308 if (curr->get_type() == THREAD_CREATE) {
309 Thread *th = (Thread *)curr->get_location();
310 th->set_creation(curr);
313 /* Deal with new thread */
314 if (curr->get_type() == THREAD_START)
315 check_promises(NULL, curr->get_cv());
317 /* Assign reads_from values */
318 Thread *th = get_thread(curr->get_tid());
319 uint64_t value = VALUE_NONE;
320 if (curr->is_read()) {
321 const ModelAction *reads_from = curr->get_node()->get_read_from();
322 if (reads_from != NULL) {
323 value = reads_from->get_value();
324 /* Assign reads_from, perform release/acquire synchronization */
325 curr->read_from(reads_from);
326 r_modification_order(curr,reads_from);
328 /* Read from future value */
329 value = curr->get_node()->get_future_value();
330 curr->read_from(NULL);
331 Promise *valuepromise = new Promise(curr, value);
332 promises->push_back(valuepromise);
334 } else if (curr->is_write()) {
335 w_modification_order(curr);
336 resolve_promises(curr);
339 th->set_return_value(value);
341 /* Add action to list. */
343 add_action_to_lists(curr);
345 /** @todo Is there a better interface for setting the next thread rather
346 than this field/convoluted approach? Perhaps like just returning
349 /* Do not split atomic actions. */
351 nextThread = thread_current()->get_id();
353 nextThread = get_next_replay_thread();
355 Node *currnode = curr->get_node();
356 Node *parnode = currnode->get_parent();
358 if (!parnode->backtrack_empty() || !currnode->read_from_empty() ||
359 !currnode->future_value_empty() || !currnode->promise_empty())
360 if (!next_backtrack || *curr > *next_backtrack)
361 next_backtrack = curr;
363 set_backtracking(curr);
366 /** @returns whether the current partial trace is feasible. */
367 bool ModelChecker::isfeasible() {
368 return !mo_graph->checkForCycles() && !failed_promise;
371 /** Returns whether the current completed trace is feasible. */
372 bool ModelChecker::isfinalfeasible() {
373 return isfeasible() && promises->size() == 0;
376 /** Close out a RMWR by converting previous RMWR into a RMW or READ. */
377 ModelAction * ModelChecker::process_rmw(ModelAction *act) {
378 int tid = id_to_int(act->get_tid());
379 ModelAction *lastread = get_last_action(tid);
380 lastread->process_rmw(act);
382 mo_graph->addRMWEdge(lastread->get_reads_from(), lastread);
387 * Updates the mo_graph with the constraints imposed from the current read.
388 * @param curr The current action. Must be a read.
389 * @param rf The action that curr reads from. Must be a write.
391 void ModelChecker::r_modification_order(ModelAction * curr, const ModelAction *rf) {
392 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
394 ASSERT(curr->is_read());
396 /* Iterate over all threads */
397 for (i = 0; i < thrd_lists->size(); i++) {
398 /* Iterate over actions in thread, starting from most recent */
399 action_list_t *list = &(*thrd_lists)[i];
400 action_list_t::reverse_iterator rit;
401 for (rit = list->rbegin(); rit != list->rend(); rit++) {
402 ModelAction *act = *rit;
404 /* Include at most one act per-thread that "happens before" curr */
405 if (act->happens_before(curr)) {
406 if (act->is_read()) {
407 const ModelAction *prevreadfrom = act->get_reads_from();
408 if (prevreadfrom != NULL && rf != prevreadfrom)
409 mo_graph->addEdge(prevreadfrom, rf);
410 } else if (rf != act) {
411 mo_graph->addEdge(act, rf);
419 /** Updates the mo_graph with the constraints imposed from the current read. */
420 void ModelChecker::post_r_modification_order(ModelAction *curr, const ModelAction *rf)
422 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
424 ASSERT(curr->is_read());
426 /* Iterate over all threads */
427 for (i = 0; i < thrd_lists->size(); i++) {
428 /* Iterate over actions in thread, starting from most recent */
429 action_list_t *list = &(*thrd_lists)[i];
430 action_list_t::reverse_iterator rit;
431 ModelAction *lastact = NULL;
433 /* Find last action that happens after curr */
434 for (rit = list->rbegin(); rit != list->rend(); rit++) {
435 ModelAction *act = *rit;
436 if (curr->happens_before(act)) {
442 /* Include at most one act per-thread that "happens before" curr */
443 if (lastact != NULL) {
444 if (lastact->is_read()) {
445 const ModelAction *postreadfrom = lastact->get_reads_from();
446 if (postreadfrom != NULL&&rf != postreadfrom)
447 mo_graph->addEdge(rf, postreadfrom);
448 } else if (rf != lastact) {
449 mo_graph->addEdge(rf, lastact);
457 * Updates the mo_graph with the constraints imposed from the current write.
458 * @param curr The current action. Must be a write.
460 void ModelChecker::w_modification_order(ModelAction * curr) {
461 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
463 ASSERT(curr->is_write());
465 if (curr->is_seqcst()) {
466 /* We have to at least see the last sequentially consistent write,
467 so we are initialized. */
468 ModelAction *last_seq_cst = get_last_seq_cst(curr->get_location());
469 if (last_seq_cst != NULL)
470 mo_graph->addEdge(last_seq_cst, curr);
473 /* Iterate over all threads */
474 for (i = 0; i < thrd_lists->size(); i++) {
475 /* Iterate over actions in thread, starting from most recent */
476 action_list_t *list = &(*thrd_lists)[i];
477 action_list_t::reverse_iterator rit;
478 for (rit = list->rbegin(); rit != list->rend(); rit++) {
479 ModelAction *act = *rit;
481 /* Include at most one act per-thread that "happens before" curr */
482 if (act->happens_before(curr)) {
484 mo_graph->addEdge(act->get_reads_from(), curr);
486 mo_graph->addEdge(act, curr);
488 } else if (act->is_read() && !act->is_synchronizing(curr) &&
489 !act->same_thread(curr)) {
490 /* We have an action that:
491 (1) did not happen before us
492 (2) is a read and we are a write
493 (3) cannot synchronize with us
494 (4) is in a different thread
496 that read could potentially read from our write.
498 if (act->get_node()->add_future_value(curr->get_value()) &&
499 (!next_backtrack || *act > *next_backtrack))
500 next_backtrack = act;
507 * Finds the head(s) of the release sequence(s) containing a given ModelAction.
508 * The ModelAction under consideration is expected to be taking part in
509 * release/acquire synchronization as an object of the "reads from" relation.
510 * Note that this can only provide release sequence support for RMW chains
511 * which do not read from the future, as those actions cannot be traced until
512 * their "promise" is fulfilled. Similarly, we may not even establish the
513 * presence of a release sequence with certainty, as some modification order
514 * constraints may be decided further in the future. Thus, this function
515 * "returns" two pieces of data: a pass-by-reference vector of @a release_heads
516 * and a boolean representing certainty.
518 * @todo Finish lazy updating, when promises are fulfilled in the future
519 * @param rf The action that might be part of a release sequence. Must be a
521 * @param release_heads A pass-by-reference style return parameter. After
522 * execution of this function, release_heads will contain the heads of all the
523 * relevant release sequences, if any exists
524 * @return true, if the ModelChecker is certain that release_heads is complete;
527 bool ModelChecker::release_seq_head(const ModelAction *rf,
528 std::vector<const ModelAction *> *release_heads) const
530 ASSERT(rf->is_write());
532 /* read from future: need to settle this later */
533 return false; /* incomplete */
535 if (rf->is_release())
536 release_heads->push_back(rf);
538 if (rf->is_acquire())
539 return true; /* complete */
540 return release_seq_head(rf->get_reads_from(), release_heads);
542 if (rf->is_release())
543 return true; /* complete */
545 /* else relaxed write; check modification order for contiguous subsequence
546 * -> rf must be same thread as release */
547 int tid = id_to_int(rf->get_tid());
548 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(rf->get_location());
549 action_list_t *list = &(*thrd_lists)[tid];
550 action_list_t::const_reverse_iterator rit;
552 /* Find rf in the thread list */
553 for (rit = list->rbegin(); rit != list->rend(); rit++)
557 /* Find the last write/release */
558 for (; rit != list->rend(); rit++)
559 if ((*rit)->is_release())
561 if (rit == list->rend()) {
562 /* No write-release in this thread */
563 return true; /* complete */
565 ModelAction *release = *rit;
567 ASSERT(rf->same_thread(release));
570 for (unsigned int i = 0; i < thrd_lists->size(); i++) {
571 if (id_to_int(rf->get_tid()) == (int)i)
573 list = &(*thrd_lists)[i];
574 for (rit = list->rbegin(); rit != list->rend(); rit++) {
575 const ModelAction *act = *rit;
576 if (!act->is_write())
578 /* Reach synchronization -> this thread is complete */
579 if (act->happens_before(release))
581 if (rf->happens_before(act))
584 /* Check modification order */
585 if (mo_graph->checkReachable(rf, act))
588 if (mo_graph->checkReachable(act, release))
589 /* act --mo--> release */
591 if (mo_graph->checkReachable(release, act) &&
592 mo_graph->checkReachable(act, rf)) {
593 /* release --mo-> act --mo--> rf */
594 return true; /* complete */
601 release_heads->push_back(release);
606 * A public interface for getting the release sequence head(s) with which a
607 * given ModelAction must synchronize. This function only returns a non-empty
608 * result when it can locate a release sequence head with certainty. Otherwise,
609 * it may mark the internal state of the ModelChecker so that it will handle
610 * the release sequence at a later time, causing @a act to update its
611 * synchronization at some later point in execution.
612 * @param act The 'acquire' action that may read from a release sequence
613 * @param release_heads A pass-by-reference return parameter. Will be filled
614 * with the head(s) of the release sequence(s), if they exists with certainty.
615 * @see ModelChecker::release_seq_head
617 void ModelChecker::get_release_seq_heads(ModelAction *act,
618 std::vector<const ModelAction *> *release_heads)
620 const ModelAction *rf = act->get_reads_from();
622 complete = release_seq_head(rf, release_heads);
624 /** @todo complete lazy checking */
629 * Performs various bookkeeping operations for the current ModelAction. For
630 * instance, adds action to the per-object, per-thread action vector and to the
631 * action trace list of all thread actions.
633 * @param act is the ModelAction to add.
635 void ModelChecker::add_action_to_lists(ModelAction *act)
637 int tid = id_to_int(act->get_tid());
638 action_trace->push_back(act);
640 obj_map->get_safe_ptr(act->get_location())->push_back(act);
642 std::vector<action_list_t> *vec = obj_thrd_map->get_safe_ptr(act->get_location());
643 if (tid >= (int)vec->size())
644 vec->resize(next_thread_id);
645 (*vec)[tid].push_back(act);
647 if ((int)thrd_last_action->size() <= tid)
648 thrd_last_action->resize(get_num_threads());
649 (*thrd_last_action)[tid] = act;
652 ModelAction * ModelChecker::get_last_action(thread_id_t tid)
654 int nthreads = get_num_threads();
655 if ((int)thrd_last_action->size() < nthreads)
656 thrd_last_action->resize(nthreads);
657 return (*thrd_last_action)[id_to_int(tid)];
661 * Gets the last memory_order_seq_cst action (in the total global sequence)
662 * performed on a particular object (i.e., memory location).
663 * @param location The object location to check
664 * @return The last seq_cst action performed
666 ModelAction * ModelChecker::get_last_seq_cst(const void *location)
668 action_list_t *list = obj_map->get_safe_ptr(location);
669 /* Find: max({i in dom(S) | seq_cst(t_i) && isWrite(t_i) && samevar(t_i, t)}) */
670 action_list_t::reverse_iterator rit;
671 for (rit = list->rbegin(); rit != list->rend(); rit++)
672 if ((*rit)->is_write() && (*rit)->is_seqcst())
677 ModelAction * ModelChecker::get_parent_action(thread_id_t tid)
679 ModelAction *parent = get_last_action(tid);
681 parent = get_thread(tid)->get_creation();
686 * Returns the clock vector for a given thread.
687 * @param tid The thread whose clock vector we want
688 * @return Desired clock vector
690 ClockVector * ModelChecker::get_cv(thread_id_t tid)
692 return get_parent_action(tid)->get_cv();
696 * Resolve a set of Promises with a current write. The set is provided in the
697 * Node corresponding to @a write.
698 * @param write The ModelAction that is fulfilling Promises
700 void ModelChecker::resolve_promises(ModelAction *write)
702 for (unsigned int i = 0, promise_index = 0; promise_index < promises->size(); i++) {
703 Promise *promise = (*promises)[promise_index];
704 if (write->get_node()->get_promise(i)) {
705 ModelAction *read = promise->get_action();
706 read->read_from(write);
707 r_modification_order(read, write);
708 post_r_modification_order(read, write);
709 promises->erase(promises->begin() + promise_index);
716 * Compute the set of promises that could potentially be satisfied by this
717 * action. Note that the set computation actually appears in the Node, not in
719 * @param curr The ModelAction that may satisfy promises
721 void ModelChecker::compute_promises(ModelAction *curr)
723 for (unsigned int i = 0; i < promises->size(); i++) {
724 Promise *promise = (*promises)[i];
725 const ModelAction *act = promise->get_action();
726 if (!act->happens_before(curr) &&
728 !act->is_synchronizing(curr) &&
729 !act->same_thread(curr) &&
730 promise->get_value() == curr->get_value()) {
731 curr->get_node()->set_promise(i);
736 /** Checks promises in response to change in ClockVector Threads. */
737 void ModelChecker::check_promises(ClockVector *old_cv, ClockVector *merge_cv)
739 for (unsigned int i = 0; i < promises->size(); i++) {
740 Promise *promise = (*promises)[i];
741 const ModelAction *act = promise->get_action();
742 if ((old_cv == NULL || !old_cv->synchronized_since(act)) &&
743 merge_cv->synchronized_since(act)) {
744 //This thread is no longer able to send values back to satisfy the promise
745 int num_synchronized_threads = promise->increment_threads();
746 if (num_synchronized_threads == model->get_num_threads()) {
748 failed_promise = true;
756 * Build up an initial set of all past writes that this 'read' action may read
757 * from. This set is determined by the clock vector's "happens before"
759 * @param curr is the current ModelAction that we are exploring; it must be a
762 void ModelChecker::build_reads_from_past(ModelAction *curr)
764 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
766 ASSERT(curr->is_read());
768 ModelAction *last_seq_cst = NULL;
770 /* Track whether this object has been initialized */
771 bool initialized = false;
773 if (curr->is_seqcst()) {
774 last_seq_cst = get_last_seq_cst(curr->get_location());
775 /* We have to at least see the last sequentially consistent write,
776 so we are initialized. */
777 if (last_seq_cst != NULL)
781 /* Iterate over all threads */
782 for (i = 0; i < thrd_lists->size(); i++) {
783 /* Iterate over actions in thread, starting from most recent */
784 action_list_t *list = &(*thrd_lists)[i];
785 action_list_t::reverse_iterator rit;
786 for (rit = list->rbegin(); rit != list->rend(); rit++) {
787 ModelAction *act = *rit;
789 /* Only consider 'write' actions */
790 if (!act->is_write())
793 /* Don't consider more than one seq_cst write if we are a seq_cst read. */
794 if (!act->is_seqcst() || !curr->is_seqcst() || act == last_seq_cst) {
795 DEBUG("Adding action to may_read_from:\n");
800 curr->get_node()->add_read_from(act);
803 /* Include at most one act per-thread that "happens before" curr */
804 if (act->happens_before(curr)) {
812 /** @todo Need a more informative way of reporting errors. */
813 printf("ERROR: may read from uninitialized atomic\n");
816 if (DBG_ENABLED() || !initialized) {
817 printf("Reached read action:\n");
819 printf("Printing may_read_from\n");
820 curr->get_node()->print_may_read_from();
821 printf("End printing may_read_from\n");
827 static void print_list(action_list_t *list)
829 action_list_t::iterator it;
831 printf("---------------------------------------------------------------------\n");
834 for (it = list->begin(); it != list->end(); it++) {
837 printf("---------------------------------------------------------------------\n");
840 void ModelChecker::print_summary()
843 printf("Number of executions: %d\n", num_executions);
844 printf("Total nodes created: %d\n", node_stack->get_total_nodes());
848 if (!isfinalfeasible())
849 printf("INFEASIBLE EXECUTION!\n");
850 print_list(action_trace);
855 * Add a Thread to the system for the first time. Should only be called once
857 * @param t The Thread to add
859 void ModelChecker::add_thread(Thread *t)
861 thread_map->put(id_to_int(t->get_id()), t);
862 scheduler->add_thread(t);
865 void ModelChecker::remove_thread(Thread *t)
867 scheduler->remove_thread(t);
871 * Switch from a user-context to the "master thread" context (a.k.a. system
872 * context). This switch is made with the intention of exploring a particular
873 * model-checking action (described by a ModelAction object). Must be called
874 * from a user-thread context.
875 * @param act The current action that will be explored. May be NULL, although
876 * there is little reason to switch to the model-checker without an action to
877 * explore (note: act == NULL is sometimes used as a hack to allow a thread to
878 * yield control without performing any progress; see thrd_join()).
879 * @return Return status from the 'swap' call (i.e., success/fail, 0/-1)
881 int ModelChecker::switch_to_master(ModelAction *act)
884 Thread *old = thread_current();
885 set_current_action(act);
886 old->set_state(THREAD_READY);
887 return Thread::swap(old, &system_context);
891 * Takes the next step in the execution, if possible.
892 * @return Returns true (success) if a step was taken and false otherwise.
894 bool ModelChecker::take_step() {
897 curr = thread_current();
899 if (curr->get_state() == THREAD_READY) {
900 check_current_action();
901 scheduler->add_thread(curr);
902 } else if (curr->get_state() == THREAD_RUNNING) {
903 /* Stopped while running; i.e., completed */
909 next = scheduler->next_thread();
911 /* Infeasible -> don't take any more steps */
916 next->set_state(THREAD_RUNNING);
917 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
919 /* next == NULL -> don't take any more steps */
922 /* Return false only if swap fails with an error */
923 return (Thread::swap(&system_context, next) == 0);
926 /** Runs the current execution until threre are no more steps to take. */
927 void ModelChecker::finish_execution() {