8 #include "snapshot-interface.h"
10 #include "clockvector.h"
11 #include "cyclegraph.h"
16 #define INITIAL_THREAD_ID 0
20 /** @brief Constructor */
21 ModelChecker::ModelChecker(struct model_params params) :
22 /* Initialize default scheduler */
24 scheduler(new Scheduler()),
26 num_feasible_executions(0),
28 earliest_diverge(NULL),
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 lock_waiters_map(new HashTable<const void *, action_list_t, uintptr_t, 4>()),
33 obj_thrd_map(new HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 >()),
34 promises(new std::vector<Promise *>()),
35 futurevalues(new std::vector<struct PendingFutureValue>()),
36 pending_acq_rel_seq(new std::vector<ModelAction *>()),
37 thrd_last_action(new std::vector<ModelAction *>(1)),
38 node_stack(new NodeStack()),
39 mo_graph(new CycleGraph()),
40 failed_promise(false),
41 too_many_reads(false),
43 bad_synchronization(false)
45 /* Allocate this "size" on the snapshotting heap */
46 priv = (struct model_snapshot_members *)calloc(1, sizeof(*priv));
47 /* First thread created will have id INITIAL_THREAD_ID */
48 priv->next_thread_id = INITIAL_THREAD_ID;
51 /** @brief Destructor */
52 ModelChecker::~ModelChecker()
54 for (int i = 0; i < get_num_threads(); i++)
55 delete thread_map->get(i);
60 delete lock_waiters_map;
63 for (unsigned int i = 0; i < promises->size(); i++)
64 delete (*promises)[i];
67 delete pending_acq_rel_seq;
69 delete thrd_last_action;
76 * Restores user program to initial state and resets all model-checker data
79 void ModelChecker::reset_to_initial_state()
81 DEBUG("+++ Resetting to initial state +++\n");
82 node_stack->reset_execution();
83 failed_promise = false;
84 too_many_reads = false;
85 bad_synchronization = false;
87 snapshotObject->backTrackBeforeStep(0);
90 /** @return a thread ID for a new Thread */
91 thread_id_t ModelChecker::get_next_id()
93 return priv->next_thread_id++;
96 /** @return the number of user threads created during this execution */
97 int ModelChecker::get_num_threads()
99 return priv->next_thread_id;
102 /** @return a sequence number for a new ModelAction */
103 modelclock_t ModelChecker::get_next_seq_num()
105 return ++priv->used_sequence_numbers;
109 * @brief Choose the next thread to execute.
111 * This function chooses the next thread that should execute. It can force the
112 * adjacency of read/write portions of a RMW action, force THREAD_CREATE to be
113 * followed by a THREAD_START, or it can enforce execution replay/backtracking.
114 * The model-checker may have no preference regarding the next thread (i.e.,
115 * when exploring a new execution ordering), in which case this will return
117 * @param curr The current ModelAction. This action might guide the choice of
119 * @return The next thread to run. If the model-checker has no preference, NULL.
121 Thread * ModelChecker::get_next_thread(ModelAction *curr)
126 /* Do not split atomic actions. */
128 return thread_current();
129 /* The THREAD_CREATE action points to the created Thread */
130 else if (curr->get_type() == THREAD_CREATE)
131 return (Thread *)curr->get_location();
134 /* Have we completed exploring the preselected path? */
138 /* Else, we are trying to replay an execution */
139 ModelAction *next = node_stack->get_next()->get_action();
141 if (next == diverge) {
142 if (earliest_diverge == NULL || *diverge < *earliest_diverge)
143 earliest_diverge=diverge;
145 Node *nextnode = next->get_node();
146 /* Reached divergence point */
147 if (nextnode->increment_promise()) {
148 /* The next node will try to satisfy a different set of promises. */
149 tid = next->get_tid();
150 node_stack->pop_restofstack(2);
151 } else if (nextnode->increment_read_from()) {
152 /* The next node will read from a different value. */
153 tid = next->get_tid();
154 node_stack->pop_restofstack(2);
155 } else if (nextnode->increment_future_value()) {
156 /* The next node will try to read from a different future value. */
157 tid = next->get_tid();
158 node_stack->pop_restofstack(2);
160 /* Make a different thread execute for next step */
161 Node *node = nextnode->get_parent();
162 tid = node->get_next_backtrack();
163 node_stack->pop_restofstack(1);
164 if (diverge==earliest_diverge) {
165 earliest_diverge=node->get_action();
168 DEBUG("*** Divergence point ***\n");
172 tid = next->get_tid();
174 DEBUG("*** ModelChecker chose next thread = %d ***\n", tid);
175 ASSERT(tid != THREAD_ID_T_NONE);
176 return thread_map->get(id_to_int(tid));
180 * Queries the model-checker for more executions to explore and, if one
181 * exists, resets the model-checker state to execute a new execution.
183 * @return If there are more executions to explore, return true. Otherwise,
186 bool ModelChecker::next_execution()
191 if (isfinalfeasible()) {
192 printf("Earliest divergence point since last feasible execution:\n");
193 if (earliest_diverge)
194 earliest_diverge->print();
196 printf("(Not set)\n");
198 earliest_diverge = NULL;
199 num_feasible_executions++;
202 if (isfinalfeasible() || DBG_ENABLED())
205 if ((diverge = get_next_backtrack()) == NULL)
209 printf("Next execution will diverge at:\n");
213 reset_to_initial_state();
217 ModelAction * ModelChecker::get_last_conflict(ModelAction *act)
219 switch (act->get_type()) {
223 /* linear search: from most recent to oldest */
224 action_list_t *list = obj_map->get_safe_ptr(act->get_location());
225 action_list_t::reverse_iterator rit;
226 for (rit = list->rbegin(); rit != list->rend(); rit++) {
227 ModelAction *prev = *rit;
228 if (act->is_synchronizing(prev))
234 case ATOMIC_TRYLOCK: {
235 /* linear search: from most recent to oldest */
236 action_list_t *list = obj_map->get_safe_ptr(act->get_location());
237 action_list_t::reverse_iterator rit;
238 for (rit = list->rbegin(); rit != list->rend(); rit++) {
239 ModelAction *prev = *rit;
240 if (act->is_conflicting_lock(prev))
245 case ATOMIC_UNLOCK: {
246 /* linear search: from most recent to oldest */
247 action_list_t *list = obj_map->get_safe_ptr(act->get_location());
248 action_list_t::reverse_iterator rit;
249 for (rit = list->rbegin(); rit != list->rend(); rit++) {
250 ModelAction *prev = *rit;
251 if (!act->same_thread(prev)&&prev->is_failed_trylock())
262 /** This method find backtracking points where we should try to
263 * reorder the parameter ModelAction against.
265 * @param the ModelAction to find backtracking points for.
267 void ModelChecker::set_backtracking(ModelAction *act)
269 Thread *t = get_thread(act);
270 ModelAction * prev = get_last_conflict(act);
274 Node * node = prev->get_node()->get_parent();
276 int low_tid, high_tid;
277 if (node->is_enabled(t)) {
278 low_tid = id_to_int(act->get_tid());
279 high_tid = low_tid+1;
282 high_tid = get_num_threads();
285 for(int i = low_tid; i < high_tid; i++) {
286 thread_id_t tid = int_to_id(i);
287 if (!node->is_enabled(tid))
290 /* Check if this has been explored already */
291 if (node->has_been_explored(tid))
294 /* See if fairness allows */
295 if (model->params.fairwindow != 0 && !node->has_priority(tid)) {
297 for(int t=0;t<node->get_num_threads();t++) {
298 thread_id_t tother=int_to_id(t);
299 if (node->is_enabled(tother) && node->has_priority(tother)) {
308 /* Cache the latest backtracking point */
309 if (!priv->next_backtrack || *prev > *priv->next_backtrack)
310 priv->next_backtrack = prev;
312 /* If this is a new backtracking point, mark the tree */
313 if (!node->set_backtrack(tid))
315 DEBUG("Setting backtrack: conflict = %d, instead tid = %d\n",
316 prev->get_tid(), t->get_id());
325 * Returns last backtracking point. The model checker will explore a different
326 * path for this point in the next execution.
327 * @return The ModelAction at which the next execution should diverge.
329 ModelAction * ModelChecker::get_next_backtrack()
331 ModelAction *next = priv->next_backtrack;
332 priv->next_backtrack = NULL;
337 * Processes a read or rmw model action.
338 * @param curr is the read model action to process.
339 * @param second_part_of_rmw is boolean that is true is this is the second action of a rmw.
340 * @return True if processing this read updates the mo_graph.
342 bool ModelChecker::process_read(ModelAction *curr, bool second_part_of_rmw)
345 bool updated = false;
347 const ModelAction *reads_from = curr->get_node()->get_read_from();
348 if (reads_from != NULL) {
349 mo_graph->startChanges();
351 value = reads_from->get_value();
352 bool r_status = false;
354 if (!second_part_of_rmw) {
355 check_recency(curr, reads_from);
356 r_status = r_modification_order(curr, reads_from);
360 if (!second_part_of_rmw&&!isfeasible()&&(curr->get_node()->increment_read_from()||curr->get_node()->increment_future_value())) {
361 mo_graph->rollbackChanges();
362 too_many_reads = false;
366 curr->read_from(reads_from);
367 mo_graph->commitChanges();
369 } else if (!second_part_of_rmw) {
370 /* Read from future value */
371 value = curr->get_node()->get_future_value();
372 modelclock_t expiration = curr->get_node()->get_future_value_expiration();
373 curr->read_from(NULL);
374 Promise *valuepromise = new Promise(curr, value, expiration);
375 promises->push_back(valuepromise);
377 get_thread(curr)->set_return_value(value);
383 * Processes a lock, trylock, or unlock model action. @param curr is
384 * the read model action to process.
386 * The try lock operation checks whether the lock is taken. If not,
387 * it falls to the normal lock operation case. If so, it returns
390 * The lock operation has already been checked that it is enabled, so
391 * it just grabs the lock and synchronizes with the previous unlock.
393 * The unlock operation has to re-enable all of the threads that are
394 * waiting on the lock.
396 * @return True if synchronization was updated; false otherwise
398 bool ModelChecker::process_mutex(ModelAction *curr) {
399 std::mutex *mutex = (std::mutex *)curr->get_location();
400 struct std::mutex_state *state = mutex->get_state();
401 switch (curr->get_type()) {
402 case ATOMIC_TRYLOCK: {
403 bool success = !state->islocked;
404 curr->set_try_lock(success);
406 get_thread(curr)->set_return_value(0);
409 get_thread(curr)->set_return_value(1);
411 //otherwise fall into the lock case
413 if (curr->get_cv()->getClock(state->alloc_tid) <= state->alloc_clock) {
414 printf("Lock access before initialization\n");
417 state->islocked = true;
418 ModelAction *unlock = get_last_unlock(curr);
419 //synchronize with the previous unlock statement
420 if (unlock != NULL) {
421 curr->synchronize_with(unlock);
426 case ATOMIC_UNLOCK: {
428 state->islocked = false;
429 //wake up the other threads
430 action_list_t *waiters = lock_waiters_map->get_safe_ptr(curr->get_location());
431 //activate all the waiting threads
432 for (action_list_t::iterator rit = waiters->begin(); rit != waiters->end(); rit++) {
433 scheduler->add_thread(get_thread((*rit)->get_tid()));
445 * Process a write ModelAction
446 * @param curr The ModelAction to process
447 * @return True if the mo_graph was updated or promises were resolved
449 bool ModelChecker::process_write(ModelAction *curr)
451 bool updated_mod_order = w_modification_order(curr);
452 bool updated_promises = resolve_promises(curr);
454 if (promises->size() == 0) {
455 for (unsigned int i = 0; i < futurevalues->size(); i++) {
456 struct PendingFutureValue pfv = (*futurevalues)[i];
457 if (pfv.act->get_node()->add_future_value(pfv.value, pfv.expiration) &&
458 (!priv->next_backtrack || *pfv.act > *priv->next_backtrack))
459 priv->next_backtrack = pfv.act;
461 futurevalues->resize(0);
464 mo_graph->commitChanges();
465 get_thread(curr)->set_return_value(VALUE_NONE);
466 return updated_mod_order || updated_promises;
470 * @brief Process the current action for thread-related activity
472 * Performs current-action processing for a THREAD_* ModelAction. Proccesses
473 * may include setting Thread status, completing THREAD_FINISH/THREAD_JOIN
474 * synchronization, etc. This function is a no-op for non-THREAD actions
475 * (e.g., ATOMIC_{READ,WRITE,RMW,LOCK}, etc.)
477 * @param curr The current action
478 * @return True if synchronization was updated
480 bool ModelChecker::process_thread_action(ModelAction *curr)
482 bool synchronized = false;
484 switch (curr->get_type()) {
485 case THREAD_CREATE: {
486 Thread *th = (Thread *)curr->get_location();
487 th->set_creation(curr);
491 Thread *waiting, *blocking;
492 waiting = get_thread(curr);
493 blocking = (Thread *)curr->get_location();
494 if (!blocking->is_complete()) {
495 blocking->push_wait_list(curr);
496 scheduler->sleep(waiting);
498 do_complete_join(curr);
503 case THREAD_FINISH: {
504 Thread *th = get_thread(curr);
505 while (!th->wait_list_empty()) {
506 ModelAction *act = th->pop_wait_list();
507 Thread *wake = get_thread(act);
508 scheduler->wake(wake);
509 do_complete_join(act);
516 check_promises(NULL, curr->get_cv());
527 * Initialize the current action by performing one or more of the following
528 * actions, as appropriate: merging RMWR and RMWC/RMW actions, stepping forward
529 * in the NodeStack, manipulating backtracking sets, allocating and
530 * initializing clock vectors, and computing the promises to fulfill.
532 * @param curr The current action, as passed from the user context; may be
533 * freed/invalidated after the execution of this function
534 * @return The current action, as processed by the ModelChecker. Is only the
535 * same as the parameter @a curr if this is a newly-explored action.
537 ModelAction * ModelChecker::initialize_curr_action(ModelAction *curr)
539 ModelAction *newcurr;
541 if (curr->is_rmwc() || curr->is_rmw()) {
542 newcurr = process_rmw(curr);
545 if (newcurr->is_rmw())
546 compute_promises(newcurr);
550 newcurr = node_stack->explore_action(curr, scheduler->get_enabled());
552 /* First restore type and order in case of RMW operation */
554 newcurr->copy_typeandorder(curr);
556 ASSERT(curr->get_location() == newcurr->get_location());
557 newcurr->copy_from_new(curr);
559 /* Discard duplicate ModelAction; use action from NodeStack */
562 /* Always compute new clock vector */
563 newcurr->create_cv(get_parent_action(newcurr->get_tid()));
567 /* Always compute new clock vector */
568 newcurr->create_cv(get_parent_action(newcurr->get_tid()));
570 * Perform one-time actions when pushing new ModelAction onto
573 if (newcurr->is_write())
574 compute_promises(newcurr);
580 * This method checks whether a model action is enabled at the given point.
581 * At this point, it checks whether a lock operation would be successful at this point.
582 * If not, it puts the thread in a waiter list.
583 * @param curr is the ModelAction to check whether it is enabled.
584 * @return a bool that indicates whether the action is enabled.
586 bool ModelChecker::check_action_enabled(ModelAction *curr) {
587 if (curr->is_lock()) {
588 std::mutex * lock = (std::mutex *)curr->get_location();
589 struct std::mutex_state * state = lock->get_state();
590 if (state->islocked) {
591 //Stick the action in the appropriate waiting queue
592 lock_waiters_map->get_safe_ptr(curr->get_location())->push_back(curr);
601 * This is the heart of the model checker routine. It performs model-checking
602 * actions corresponding to a given "current action." Among other processes, it
603 * calculates reads-from relationships, updates synchronization clock vectors,
604 * forms a memory_order constraints graph, and handles replay/backtrack
605 * execution when running permutations of previously-observed executions.
607 * @param curr The current action to process
608 * @return The next Thread that must be executed. May be NULL if ModelChecker
609 * makes no choice (e.g., according to replay execution, combining RMW actions,
612 Thread * ModelChecker::check_current_action(ModelAction *curr)
616 bool second_part_of_rmw = curr->is_rmwc() || curr->is_rmw();
618 if (!check_action_enabled(curr)) {
619 /* Make the execution look like we chose to run this action
620 * much later, when a lock is actually available to release */
621 get_current_thread()->set_pending(curr);
622 remove_thread(get_current_thread());
623 return get_next_thread(NULL);
626 ModelAction *newcurr = initialize_curr_action(curr);
628 /* Add the action to lists before any other model-checking tasks */
629 if (!second_part_of_rmw)
630 add_action_to_lists(newcurr);
632 /* Build may_read_from set for newly-created actions */
633 if (curr == newcurr && curr->is_read())
634 build_reads_from_past(curr);
637 /* Initialize work_queue with the "current action" work */
638 work_queue_t work_queue(1, CheckCurrWorkEntry(curr));
640 while (!work_queue.empty()) {
641 WorkQueueEntry work = work_queue.front();
642 work_queue.pop_front();
645 case WORK_CHECK_CURR_ACTION: {
646 ModelAction *act = work.action;
647 bool update = false; /* update this location's release seq's */
648 bool update_all = false; /* update all release seq's */
650 if (process_thread_action(curr))
653 if (act->is_read() && process_read(act, second_part_of_rmw))
656 if (act->is_write() && process_write(act))
659 if (act->is_mutex_op() && process_mutex(act))
663 work_queue.push_back(CheckRelSeqWorkEntry(NULL));
665 work_queue.push_back(CheckRelSeqWorkEntry(act->get_location()));
668 case WORK_CHECK_RELEASE_SEQ:
669 resolve_release_sequences(work.location, &work_queue);
671 case WORK_CHECK_MO_EDGES: {
672 /** @todo Complete verification of work_queue */
673 ModelAction *act = work.action;
674 bool updated = false;
676 if (act->is_read()) {
677 const ModelAction *rf = act->get_reads_from();
678 if (rf != NULL && r_modification_order(act, rf))
681 if (act->is_write()) {
682 if (w_modification_order(act))
685 mo_graph->commitChanges();
688 work_queue.push_back(CheckRelSeqWorkEntry(act->get_location()));
697 check_curr_backtracking(curr);
699 set_backtracking(curr);
701 return get_next_thread(curr);
705 * Complete a THREAD_JOIN operation, by synchronizing with the THREAD_FINISH
706 * operation from the Thread it is joining with. Must be called after the
707 * completion of the Thread in question.
708 * @param join The THREAD_JOIN action
710 void ModelChecker::do_complete_join(ModelAction *join)
712 Thread *blocking = (Thread *)join->get_location();
713 ModelAction *act = get_last_action(blocking->get_id());
714 join->synchronize_with(act);
717 void ModelChecker::check_curr_backtracking(ModelAction * curr) {
718 Node *currnode = curr->get_node();
719 Node *parnode = currnode->get_parent();
721 if ((!parnode->backtrack_empty() ||
722 !currnode->read_from_empty() ||
723 !currnode->future_value_empty() ||
724 !currnode->promise_empty())
725 && (!priv->next_backtrack ||
726 *curr > *priv->next_backtrack)) {
727 priv->next_backtrack = curr;
731 bool ModelChecker::promises_expired() {
732 for (unsigned int promise_index = 0; promise_index < promises->size(); promise_index++) {
733 Promise *promise = (*promises)[promise_index];
734 if (promise->get_expiration()<priv->used_sequence_numbers) {
741 /** @return whether the current partial trace must be a prefix of a
743 bool ModelChecker::isfeasibleprefix() {
744 return promises->size() == 0 && pending_acq_rel_seq->size() == 0;
747 /** @return whether the current partial trace is feasible. */
748 bool ModelChecker::isfeasible() {
749 if (DBG_ENABLED() && mo_graph->checkForRMWViolation())
750 DEBUG("Infeasible: RMW violation\n");
752 return !mo_graph->checkForRMWViolation() && isfeasibleotherthanRMW();
755 /** @return whether the current partial trace is feasible other than
756 * multiple RMW reading from the same store. */
757 bool ModelChecker::isfeasibleotherthanRMW() {
759 if (mo_graph->checkForCycles())
760 DEBUG("Infeasible: modification order cycles\n");
762 DEBUG("Infeasible: failed promise\n");
764 DEBUG("Infeasible: too many reads\n");
765 if (bad_synchronization)
766 DEBUG("Infeasible: bad synchronization ordering\n");
767 if (promises_expired())
768 DEBUG("Infeasible: promises expired\n");
770 return !mo_graph->checkForCycles() && !failed_promise && !too_many_reads && !bad_synchronization && !promises_expired();
773 /** Returns whether the current completed trace is feasible. */
774 bool ModelChecker::isfinalfeasible() {
775 if (DBG_ENABLED() && promises->size() != 0)
776 DEBUG("Infeasible: unrevolved promises\n");
778 return isfeasible() && promises->size() == 0;
781 /** Close out a RMWR by converting previous RMWR into a RMW or READ. */
782 ModelAction * ModelChecker::process_rmw(ModelAction *act) {
783 int tid = id_to_int(act->get_tid());
784 ModelAction *lastread = get_last_action(tid);
785 lastread->process_rmw(act);
786 if (act->is_rmw() && lastread->get_reads_from()!=NULL) {
787 mo_graph->addRMWEdge(lastread->get_reads_from(), lastread);
788 mo_graph->commitChanges();
794 * Checks whether a thread has read from the same write for too many times
795 * without seeing the effects of a later write.
798 * 1) there must a different write that we could read from that would satisfy the modification order,
799 * 2) we must have read from the same value in excess of maxreads times, and
800 * 3) that other write must have been in the reads_from set for maxreads times.
802 * If so, we decide that the execution is no longer feasible.
804 void ModelChecker::check_recency(ModelAction *curr, const ModelAction *rf) {
805 if (params.maxreads != 0) {
807 if (curr->get_node()->get_read_from_size() <= 1)
809 //Must make sure that execution is currently feasible... We could
810 //accidentally clear by rolling back
813 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
814 int tid = id_to_int(curr->get_tid());
817 if ((int)thrd_lists->size() <= tid)
819 action_list_t *list = &(*thrd_lists)[tid];
821 action_list_t::reverse_iterator rit = list->rbegin();
823 for (; (*rit) != curr; rit++)
825 /* go past curr now */
828 action_list_t::reverse_iterator ritcopy = rit;
829 //See if we have enough reads from the same value
831 for (; count < params.maxreads; rit++,count++) {
832 if (rit==list->rend())
834 ModelAction *act = *rit;
838 if (act->get_reads_from() != rf)
840 if (act->get_node()->get_read_from_size() <= 1)
843 for (int i = 0; i<curr->get_node()->get_read_from_size(); i++) {
845 const ModelAction * write = curr->get_node()->get_read_from_at(i);
847 //Need a different write
851 /* Test to see whether this is a feasible write to read from*/
852 mo_graph->startChanges();
853 r_modification_order(curr, write);
854 bool feasiblereadfrom = isfeasible();
855 mo_graph->rollbackChanges();
857 if (!feasiblereadfrom)
861 bool feasiblewrite = true;
862 //new we need to see if this write works for everyone
864 for (int loop = count; loop>0; loop--,rit++) {
865 ModelAction *act=*rit;
866 bool foundvalue = false;
867 for (int j = 0; j<act->get_node()->get_read_from_size(); j++) {
868 if (act->get_node()->get_read_from_at(i)==write) {
874 feasiblewrite = false;
879 too_many_reads = true;
887 * Updates the mo_graph with the constraints imposed from the current
890 * Basic idea is the following: Go through each other thread and find
891 * the lastest action that happened before our read. Two cases:
893 * (1) The action is a write => that write must either occur before
894 * the write we read from or be the write we read from.
896 * (2) The action is a read => the write that that action read from
897 * must occur before the write we read from or be the same write.
899 * @param curr The current action. Must be a read.
900 * @param rf The action that curr reads from. Must be a write.
901 * @return True if modification order edges were added; false otherwise
903 bool ModelChecker::r_modification_order(ModelAction *curr, const ModelAction *rf)
905 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
908 ASSERT(curr->is_read());
910 /* Iterate over all threads */
911 for (i = 0; i < thrd_lists->size(); i++) {
912 /* Iterate over actions in thread, starting from most recent */
913 action_list_t *list = &(*thrd_lists)[i];
914 action_list_t::reverse_iterator rit;
915 for (rit = list->rbegin(); rit != list->rend(); rit++) {
916 ModelAction *act = *rit;
919 * Include at most one act per-thread that "happens
920 * before" curr. Don't consider reflexively.
922 if (act->happens_before(curr) && act != curr) {
923 if (act->is_write()) {
925 mo_graph->addEdge(act, rf);
929 const ModelAction *prevreadfrom = act->get_reads_from();
930 if (prevreadfrom != NULL && rf != prevreadfrom) {
931 mo_graph->addEdge(prevreadfrom, rf);
943 /** This method fixes up the modification order when we resolve a
944 * promises. The basic problem is that actions that occur after the
945 * read curr could not property add items to the modification order
948 * So for each thread, we find the earliest item that happens after
949 * the read curr. This is the item we have to fix up with additional
950 * constraints. If that action is write, we add a MO edge between
951 * the Action rf and that action. If the action is a read, we add a
952 * MO edge between the Action rf, and whatever the read accessed.
954 * @param curr is the read ModelAction that we are fixing up MO edges for.
955 * @param rf is the write ModelAction that curr reads from.
958 void ModelChecker::post_r_modification_order(ModelAction *curr, const ModelAction *rf)
960 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
962 ASSERT(curr->is_read());
964 /* Iterate over all threads */
965 for (i = 0; i < thrd_lists->size(); i++) {
966 /* Iterate over actions in thread, starting from most recent */
967 action_list_t *list = &(*thrd_lists)[i];
968 action_list_t::reverse_iterator rit;
969 ModelAction *lastact = NULL;
971 /* Find last action that happens after curr that is either not curr or a rmw */
972 for (rit = list->rbegin(); rit != list->rend(); rit++) {
973 ModelAction *act = *rit;
974 if (curr->happens_before(act) && (curr != act || curr->is_rmw())) {
980 /* Include at most one act per-thread that "happens before" curr */
981 if (lastact != NULL) {
983 //Case 1: The resolved read is a RMW, and we need to make sure
984 //that the write portion of the RMW mod order after rf
986 mo_graph->addEdge(rf, lastact);
987 } else if (lastact->is_read()) {
988 //Case 2: The resolved read is a normal read and the next
989 //operation is a read, and we need to make sure the value read
990 //is mod ordered after rf
992 const ModelAction *postreadfrom = lastact->get_reads_from();
993 if (postreadfrom != NULL&&rf != postreadfrom)
994 mo_graph->addEdge(rf, postreadfrom);
996 //Case 3: The resolved read is a normal read and the next
997 //operation is a write, and we need to make sure that the
998 //write is mod ordered after rf
1000 mo_graph->addEdge(rf, lastact);
1008 * Updates the mo_graph with the constraints imposed from the current write.
1010 * Basic idea is the following: Go through each other thread and find
1011 * the lastest action that happened before our write. Two cases:
1013 * (1) The action is a write => that write must occur before
1016 * (2) The action is a read => the write that that action read from
1017 * must occur before the current write.
1019 * This method also handles two other issues:
1021 * (I) Sequential Consistency: Making sure that if the current write is
1022 * seq_cst, that it occurs after the previous seq_cst write.
1024 * (II) Sending the write back to non-synchronizing reads.
1026 * @param curr The current action. Must be a write.
1027 * @return True if modification order edges were added; false otherwise
1029 bool ModelChecker::w_modification_order(ModelAction *curr)
1031 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
1034 ASSERT(curr->is_write());
1036 if (curr->is_seqcst()) {
1037 /* We have to at least see the last sequentially consistent write,
1038 so we are initialized. */
1039 ModelAction *last_seq_cst = get_last_seq_cst(curr);
1040 if (last_seq_cst != NULL) {
1041 mo_graph->addEdge(last_seq_cst, curr);
1046 /* Iterate over all threads */
1047 for (i = 0; i < thrd_lists->size(); i++) {
1048 /* Iterate over actions in thread, starting from most recent */
1049 action_list_t *list = &(*thrd_lists)[i];
1050 action_list_t::reverse_iterator rit;
1051 for (rit = list->rbegin(); rit != list->rend(); rit++) {
1052 ModelAction *act = *rit;
1055 * If RMW, we already have all relevant edges,
1056 * so just skip to next thread.
1057 * If normal write, we need to look at earlier
1058 * actions, so continue processing list.
1067 * Include at most one act per-thread that "happens
1070 if (act->happens_before(curr)) {
1072 * Note: if act is RMW, just add edge:
1074 * The following edge should be handled elsewhere:
1075 * readfrom(act) --mo--> act
1077 if (act->is_write())
1078 mo_graph->addEdge(act, curr);
1079 else if (act->is_read() && act->get_reads_from() != NULL)
1080 mo_graph->addEdge(act->get_reads_from(), curr);
1083 } else if (act->is_read() && !act->is_synchronizing(curr) &&
1084 !act->same_thread(curr)) {
1085 /* We have an action that:
1086 (1) did not happen before us
1087 (2) is a read and we are a write
1088 (3) cannot synchronize with us
1089 (4) is in a different thread
1091 that read could potentially read from our write.
1093 if (thin_air_constraint_may_allow(curr, act)) {
1095 (curr->is_rmw() && act->is_rmw() && curr->get_reads_from() == act->get_reads_from() && isfeasibleotherthanRMW())) {
1096 struct PendingFutureValue pfv = {curr->get_value(),curr->get_seq_number()+params.maxfuturedelay,act};
1097 futurevalues->push_back(pfv);
1107 /** Arbitrary reads from the future are not allowed. Section 29.3
1108 * part 9 places some constraints. This method checks one result of constraint
1109 * constraint. Others require compiler support. */
1110 bool ModelChecker::thin_air_constraint_may_allow(const ModelAction * writer, const ModelAction *reader) {
1111 if (!writer->is_rmw())
1114 if (!reader->is_rmw())
1117 for (const ModelAction *search = writer->get_reads_from(); search != NULL; search = search->get_reads_from()) {
1118 if (search == reader)
1120 if (search->get_tid() == reader->get_tid() &&
1121 search->happens_before(reader))
1129 * Finds the head(s) of the release sequence(s) containing a given ModelAction.
1130 * The ModelAction under consideration is expected to be taking part in
1131 * release/acquire synchronization as an object of the "reads from" relation.
1132 * Note that this can only provide release sequence support for RMW chains
1133 * which do not read from the future, as those actions cannot be traced until
1134 * their "promise" is fulfilled. Similarly, we may not even establish the
1135 * presence of a release sequence with certainty, as some modification order
1136 * constraints may be decided further in the future. Thus, this function
1137 * "returns" two pieces of data: a pass-by-reference vector of @a release_heads
1138 * and a boolean representing certainty.
1140 * @todo Finish lazy updating, when promises are fulfilled in the future
1141 * @param rf The action that might be part of a release sequence. Must be a
1143 * @param release_heads A pass-by-reference style return parameter. After
1144 * execution of this function, release_heads will contain the heads of all the
1145 * relevant release sequences, if any exists
1146 * @return true, if the ModelChecker is certain that release_heads is complete;
1149 bool ModelChecker::release_seq_head(const ModelAction *rf, rel_heads_list_t *release_heads) const
1151 /* Only check for release sequences if there are no cycles */
1152 if (mo_graph->checkForCycles())
1156 ASSERT(rf->is_write());
1158 if (rf->is_release())
1159 release_heads->push_back(rf);
1161 break; /* End of RMW chain */
1163 /** @todo Need to be smarter here... In the linux lock
1164 * example, this will run to the beginning of the program for
1166 /** @todo The way to be smarter here is to keep going until 1
1167 * thread has a release preceded by an acquire and you've seen
1170 /* acq_rel RMW is a sufficient stopping condition */
1171 if (rf->is_acquire() && rf->is_release())
1172 return true; /* complete */
1174 rf = rf->get_reads_from();
1177 /* read from future: need to settle this later */
1178 return false; /* incomplete */
1181 if (rf->is_release())
1182 return true; /* complete */
1184 /* else relaxed write; check modification order for contiguous subsequence
1185 * -> rf must be same thread as release */
1186 int tid = id_to_int(rf->get_tid());
1187 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(rf->get_location());
1188 action_list_t *list = &(*thrd_lists)[tid];
1189 action_list_t::const_reverse_iterator rit;
1191 /* Find rf in the thread list */
1192 rit = std::find(list->rbegin(), list->rend(), rf);
1193 ASSERT(rit != list->rend());
1195 /* Find the last write/release */
1196 for (; rit != list->rend(); rit++)
1197 if ((*rit)->is_release())
1199 if (rit == list->rend()) {
1200 /* No write-release in this thread */
1201 return true; /* complete */
1203 ModelAction *release = *rit;
1205 ASSERT(rf->same_thread(release));
1207 bool certain = true;
1208 for (unsigned int i = 0; i < thrd_lists->size(); i++) {
1209 if (id_to_int(rf->get_tid()) == (int)i)
1211 list = &(*thrd_lists)[i];
1213 /* Can we ensure no future writes from this thread may break
1214 * the release seq? */
1215 bool future_ordered = false;
1217 ModelAction *last = get_last_action(int_to_id(i));
1218 if (last && (rf->happens_before(last) ||
1219 last->get_type() == THREAD_FINISH))
1220 future_ordered = true;
1222 for (rit = list->rbegin(); rit != list->rend(); rit++) {
1223 const ModelAction *act = *rit;
1224 /* Reach synchronization -> this thread is complete */
1225 if (act->happens_before(release))
1227 if (rf->happens_before(act)) {
1228 future_ordered = true;
1232 /* Only writes can break release sequences */
1233 if (!act->is_write())
1236 /* Check modification order */
1237 if (mo_graph->checkReachable(rf, act)) {
1238 /* rf --mo--> act */
1239 future_ordered = true;
1242 if (mo_graph->checkReachable(act, release))
1243 /* act --mo--> release */
1245 if (mo_graph->checkReachable(release, act) &&
1246 mo_graph->checkReachable(act, rf)) {
1247 /* release --mo-> act --mo--> rf */
1248 return true; /* complete */
1252 if (!future_ordered)
1253 return false; /* This thread is uncertain */
1257 release_heads->push_back(release);
1262 * A public interface for getting the release sequence head(s) with which a
1263 * given ModelAction must synchronize. This function only returns a non-empty
1264 * result when it can locate a release sequence head with certainty. Otherwise,
1265 * it may mark the internal state of the ModelChecker so that it will handle
1266 * the release sequence at a later time, causing @a act to update its
1267 * synchronization at some later point in execution.
1268 * @param act The 'acquire' action that may read from a release sequence
1269 * @param release_heads A pass-by-reference return parameter. Will be filled
1270 * with the head(s) of the release sequence(s), if they exists with certainty.
1271 * @see ModelChecker::release_seq_head
1273 void ModelChecker::get_release_seq_heads(ModelAction *act, rel_heads_list_t *release_heads)
1275 const ModelAction *rf = act->get_reads_from();
1277 complete = release_seq_head(rf, release_heads);
1279 /* add act to 'lazy checking' list */
1280 pending_acq_rel_seq->push_back(act);
1285 * Attempt to resolve all stashed operations that might synchronize with a
1286 * release sequence for a given location. This implements the "lazy" portion of
1287 * determining whether or not a release sequence was contiguous, since not all
1288 * modification order information is present at the time an action occurs.
1290 * @param location The location/object that should be checked for release
1291 * sequence resolutions. A NULL value means to check all locations.
1292 * @param work_queue The work queue to which to add work items as they are
1294 * @return True if any updates occurred (new synchronization, new mo_graph
1297 bool ModelChecker::resolve_release_sequences(void *location, work_queue_t *work_queue)
1299 bool updated = false;
1300 std::vector<ModelAction *>::iterator it = pending_acq_rel_seq->begin();
1301 while (it != pending_acq_rel_seq->end()) {
1302 ModelAction *act = *it;
1304 /* Only resolve sequences on the given location, if provided */
1305 if (location && act->get_location() != location) {
1310 const ModelAction *rf = act->get_reads_from();
1311 rel_heads_list_t release_heads;
1313 complete = release_seq_head(rf, &release_heads);
1314 for (unsigned int i = 0; i < release_heads.size(); i++) {
1315 if (!act->has_synchronized_with(release_heads[i])) {
1316 if (act->synchronize_with(release_heads[i]))
1319 set_bad_synchronization();
1324 /* Re-check act for mo_graph edges */
1325 work_queue->push_back(MOEdgeWorkEntry(act));
1327 /* propagate synchronization to later actions */
1328 action_list_t::reverse_iterator rit = action_trace->rbegin();
1329 for (; (*rit) != act; rit++) {
1330 ModelAction *propagate = *rit;
1331 if (act->happens_before(propagate)) {
1332 propagate->synchronize_with(act);
1333 /* Re-check 'propagate' for mo_graph edges */
1334 work_queue->push_back(MOEdgeWorkEntry(propagate));
1339 it = pending_acq_rel_seq->erase(it);
1344 // If we resolved promises or data races, see if we have realized a data race.
1345 if (checkDataRaces()) {
1353 * Performs various bookkeeping operations for the current ModelAction. For
1354 * instance, adds action to the per-object, per-thread action vector and to the
1355 * action trace list of all thread actions.
1357 * @param act is the ModelAction to add.
1359 void ModelChecker::add_action_to_lists(ModelAction *act)
1361 int tid = id_to_int(act->get_tid());
1362 action_trace->push_back(act);
1364 obj_map->get_safe_ptr(act->get_location())->push_back(act);
1366 std::vector<action_list_t> *vec = obj_thrd_map->get_safe_ptr(act->get_location());
1367 if (tid >= (int)vec->size())
1368 vec->resize(priv->next_thread_id);
1369 (*vec)[tid].push_back(act);
1371 if ((int)thrd_last_action->size() <= tid)
1372 thrd_last_action->resize(get_num_threads());
1373 (*thrd_last_action)[tid] = act;
1377 * @brief Get the last action performed by a particular Thread
1378 * @param tid The thread ID of the Thread in question
1379 * @return The last action in the thread
1381 ModelAction * ModelChecker::get_last_action(thread_id_t tid) const
1383 int threadid = id_to_int(tid);
1384 if (threadid < (int)thrd_last_action->size())
1385 return (*thrd_last_action)[id_to_int(tid)];
1391 * Gets the last memory_order_seq_cst write (in the total global sequence)
1392 * performed on a particular object (i.e., memory location), not including the
1394 * @param curr The current ModelAction; also denotes the object location to
1396 * @return The last seq_cst write
1398 ModelAction * ModelChecker::get_last_seq_cst(ModelAction *curr) const
1400 void *location = curr->get_location();
1401 action_list_t *list = obj_map->get_safe_ptr(location);
1402 /* Find: max({i in dom(S) | seq_cst(t_i) && isWrite(t_i) && samevar(t_i, t)}) */
1403 action_list_t::reverse_iterator rit;
1404 for (rit = list->rbegin(); rit != list->rend(); rit++)
1405 if ((*rit)->is_write() && (*rit)->is_seqcst() && (*rit) != curr)
1411 * Gets the last unlock operation performed on a particular mutex (i.e., memory
1412 * location). This function identifies the mutex according to the current
1413 * action, which is presumed to perform on the same mutex.
1414 * @param curr The current ModelAction; also denotes the object location to
1416 * @return The last unlock operation
1418 ModelAction * ModelChecker::get_last_unlock(ModelAction *curr) const
1420 void *location = curr->get_location();
1421 action_list_t *list = obj_map->get_safe_ptr(location);
1422 /* Find: max({i in dom(S) | isUnlock(t_i) && samevar(t_i, t)}) */
1423 action_list_t::reverse_iterator rit;
1424 for (rit = list->rbegin(); rit != list->rend(); rit++)
1425 if ((*rit)->is_unlock())
1430 ModelAction * ModelChecker::get_parent_action(thread_id_t tid)
1432 ModelAction *parent = get_last_action(tid);
1434 parent = get_thread(tid)->get_creation();
1439 * Returns the clock vector for a given thread.
1440 * @param tid The thread whose clock vector we want
1441 * @return Desired clock vector
1443 ClockVector * ModelChecker::get_cv(thread_id_t tid)
1445 return get_parent_action(tid)->get_cv();
1449 * Resolve a set of Promises with a current write. The set is provided in the
1450 * Node corresponding to @a write.
1451 * @param write The ModelAction that is fulfilling Promises
1452 * @return True if promises were resolved; false otherwise
1454 bool ModelChecker::resolve_promises(ModelAction *write)
1456 bool resolved = false;
1458 for (unsigned int i = 0, promise_index = 0; promise_index < promises->size(); i++) {
1459 Promise *promise = (*promises)[promise_index];
1460 if (write->get_node()->get_promise(i)) {
1461 ModelAction *read = promise->get_action();
1462 if (read->is_rmw()) {
1463 mo_graph->addRMWEdge(write, read);
1465 read->read_from(write);
1466 //First fix up the modification order for actions that happened
1468 r_modification_order(read, write);
1469 //Next fix up the modification order for actions that happened
1471 post_r_modification_order(read, write);
1472 //Make sure the promise's value matches the write's value
1473 ASSERT(promise->get_value() == write->get_value());
1475 promises->erase(promises->begin() + promise_index);
1484 * Compute the set of promises that could potentially be satisfied by this
1485 * action. Note that the set computation actually appears in the Node, not in
1487 * @param curr The ModelAction that may satisfy promises
1489 void ModelChecker::compute_promises(ModelAction *curr)
1491 for (unsigned int i = 0; i < promises->size(); i++) {
1492 Promise *promise = (*promises)[i];
1493 const ModelAction *act = promise->get_action();
1494 if (!act->happens_before(curr) &&
1496 !act->is_synchronizing(curr) &&
1497 !act->same_thread(curr) &&
1498 promise->get_value() == curr->get_value()) {
1499 curr->get_node()->set_promise(i);
1504 /** Checks promises in response to change in ClockVector Threads. */
1505 void ModelChecker::check_promises(ClockVector *old_cv, ClockVector *merge_cv)
1507 for (unsigned int i = 0; i < promises->size(); i++) {
1508 Promise *promise = (*promises)[i];
1509 const ModelAction *act = promise->get_action();
1510 if ((old_cv == NULL || !old_cv->synchronized_since(act)) &&
1511 merge_cv->synchronized_since(act)) {
1512 //This thread is no longer able to send values back to satisfy the promise
1513 int num_synchronized_threads = promise->increment_threads();
1514 if (num_synchronized_threads == get_num_threads()) {
1515 //Promise has failed
1516 failed_promise = true;
1524 * Build up an initial set of all past writes that this 'read' action may read
1525 * from. This set is determined by the clock vector's "happens before"
1527 * @param curr is the current ModelAction that we are exploring; it must be a
1530 void ModelChecker::build_reads_from_past(ModelAction *curr)
1532 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
1534 ASSERT(curr->is_read());
1536 ModelAction *last_seq_cst = NULL;
1538 /* Track whether this object has been initialized */
1539 bool initialized = false;
1541 if (curr->is_seqcst()) {
1542 last_seq_cst = get_last_seq_cst(curr);
1543 /* We have to at least see the last sequentially consistent write,
1544 so we are initialized. */
1545 if (last_seq_cst != NULL)
1549 /* Iterate over all threads */
1550 for (i = 0; i < thrd_lists->size(); i++) {
1551 /* Iterate over actions in thread, starting from most recent */
1552 action_list_t *list = &(*thrd_lists)[i];
1553 action_list_t::reverse_iterator rit;
1554 for (rit = list->rbegin(); rit != list->rend(); rit++) {
1555 ModelAction *act = *rit;
1557 /* Only consider 'write' actions */
1558 if (!act->is_write() || act == curr)
1561 /* Don't consider more than one seq_cst write if we are a seq_cst read. */
1562 if (!curr->is_seqcst() || (!act->is_seqcst() && (last_seq_cst == NULL || !act->happens_before(last_seq_cst))) || act == last_seq_cst) {
1563 DEBUG("Adding action to may_read_from:\n");
1564 if (DBG_ENABLED()) {
1568 curr->get_node()->add_read_from(act);
1571 /* Include at most one act per-thread that "happens before" curr */
1572 if (act->happens_before(curr)) {
1580 /** @todo Need a more informative way of reporting errors. */
1581 printf("ERROR: may read from uninitialized atomic\n");
1584 if (DBG_ENABLED() || !initialized) {
1585 printf("Reached read action:\n");
1587 printf("Printing may_read_from\n");
1588 curr->get_node()->print_may_read_from();
1589 printf("End printing may_read_from\n");
1592 ASSERT(initialized);
1595 static void print_list(action_list_t *list)
1597 action_list_t::iterator it;
1599 printf("---------------------------------------------------------------------\n");
1602 for (it = list->begin(); it != list->end(); it++) {
1605 printf("---------------------------------------------------------------------\n");
1608 #if SUPPORT_MOD_ORDER_DUMP
1609 void ModelChecker::dumpGraph(char *filename) {
1611 sprintf(buffer, "%s.dot",filename);
1612 FILE *file=fopen(buffer, "w");
1613 fprintf(file, "digraph %s {\n",filename);
1614 mo_graph->dumpNodes(file);
1615 ModelAction ** thread_array=(ModelAction **)model_calloc(1, sizeof(ModelAction *)*get_num_threads());
1617 for (action_list_t::iterator it = action_trace->begin(); it != action_trace->end(); it++) {
1618 ModelAction *action=*it;
1619 if (action->is_read()) {
1620 fprintf(file, "N%u [label=\"%u, T%u\"];\n", action->get_seq_number(),action->get_seq_number(), action->get_tid());
1621 fprintf(file, "N%u -> N%u[label=\"rf\", color=red];\n", action->get_seq_number(), action->get_reads_from()->get_seq_number());
1623 if (thread_array[action->get_tid()] != NULL) {
1624 fprintf(file, "N%u -> N%u[label=\"sb\", color=blue];\n", thread_array[action->get_tid()]->get_seq_number(), action->get_seq_number());
1627 thread_array[action->get_tid()]=action;
1629 fprintf(file,"}\n");
1630 model_free(thread_array);
1635 void ModelChecker::print_summary()
1638 printf("Number of executions: %d\n", num_executions);
1639 printf("Number of feasible executions: %d\n", num_feasible_executions);
1640 printf("Total nodes created: %d\n", node_stack->get_total_nodes());
1642 #if SUPPORT_MOD_ORDER_DUMP
1644 char buffername[100];
1645 sprintf(buffername, "exec%04u", num_executions);
1646 mo_graph->dumpGraphToFile(buffername);
1647 sprintf(buffername, "graph%04u", num_executions);
1648 dumpGraph(buffername);
1651 if (!isfinalfeasible())
1652 printf("INFEASIBLE EXECUTION!\n");
1653 print_list(action_trace);
1658 * Add a Thread to the system for the first time. Should only be called once
1660 * @param t The Thread to add
1662 void ModelChecker::add_thread(Thread *t)
1664 thread_map->put(id_to_int(t->get_id()), t);
1665 scheduler->add_thread(t);
1669 * Removes a thread from the scheduler.
1670 * @param the thread to remove.
1672 void ModelChecker::remove_thread(Thread *t)
1674 scheduler->remove_thread(t);
1678 * Switch from a user-context to the "master thread" context (a.k.a. system
1679 * context). This switch is made with the intention of exploring a particular
1680 * model-checking action (described by a ModelAction object). Must be called
1681 * from a user-thread context.
1682 * @param act The current action that will be explored. Must not be NULL.
1683 * @return Return status from the 'swap' call (i.e., success/fail, 0/-1)
1685 int ModelChecker::switch_to_master(ModelAction *act)
1688 Thread *old = thread_current();
1689 set_current_action(act);
1690 old->set_state(THREAD_READY);
1691 return Thread::swap(old, &system_context);
1695 * Takes the next step in the execution, if possible.
1696 * @return Returns true (success) if a step was taken and false otherwise.
1698 bool ModelChecker::take_step() {
1702 Thread * curr = thread_current();
1704 if (curr->get_state() == THREAD_READY) {
1705 ASSERT(priv->current_action);
1707 priv->nextThread = check_current_action(priv->current_action);
1708 priv->current_action = NULL;
1710 if (curr->is_blocked() || curr->is_complete())
1711 scheduler->remove_thread(curr);
1716 Thread * next = scheduler->next_thread(priv->nextThread);
1718 /* Infeasible -> don't take any more steps */
1723 next->set_state(THREAD_RUNNING);
1724 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
1726 /* next == NULL -> don't take any more steps */
1730 if ( next->get_pending() != NULL ) {
1731 //restart a pending action
1732 set_current_action(next->get_pending());
1733 next->set_pending(NULL);
1734 next->set_state(THREAD_READY);
1738 /* Return false only if swap fails with an error */
1739 return (Thread::swap(&system_context, next) == 0);
1742 /** Runs the current execution until threre are no more steps to take. */
1743 void ModelChecker::finish_execution() {
1746 while (take_step());