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()
192 if (isfinalfeasible()) {
193 printf("Earliest divergence point since last feasible execution:\n");
194 if (earliest_diverge)
195 earliest_diverge->print(false);
197 printf("(Not set)\n");
199 earliest_diverge = NULL;
200 num_feasible_executions++;
203 DEBUG("Number of acquires waiting on pending release sequences: %lu\n",
204 pending_acq_rel_seq->size());
206 if (isfinalfeasible() || DBG_ENABLED())
209 if ((diverge = get_next_backtrack()) == NULL)
213 printf("Next execution will diverge at:\n");
217 reset_to_initial_state();
221 ModelAction * ModelChecker::get_last_conflict(ModelAction *act)
223 switch (act->get_type()) {
227 /* linear search: from most recent to oldest */
228 action_list_t *list = obj_map->get_safe_ptr(act->get_location());
229 action_list_t::reverse_iterator rit;
230 for (rit = list->rbegin(); rit != list->rend(); rit++) {
231 ModelAction *prev = *rit;
232 if (act->is_synchronizing(prev))
238 case ATOMIC_TRYLOCK: {
239 /* linear search: from most recent to oldest */
240 action_list_t *list = obj_map->get_safe_ptr(act->get_location());
241 action_list_t::reverse_iterator rit;
242 for (rit = list->rbegin(); rit != list->rend(); rit++) {
243 ModelAction *prev = *rit;
244 if (act->is_conflicting_lock(prev))
249 case ATOMIC_UNLOCK: {
250 /* linear search: from most recent to oldest */
251 action_list_t *list = obj_map->get_safe_ptr(act->get_location());
252 action_list_t::reverse_iterator rit;
253 for (rit = list->rbegin(); rit != list->rend(); rit++) {
254 ModelAction *prev = *rit;
255 if (!act->same_thread(prev)&&prev->is_failed_trylock())
266 /** This method find backtracking points where we should try to
267 * reorder the parameter ModelAction against.
269 * @param the ModelAction to find backtracking points for.
271 void ModelChecker::set_backtracking(ModelAction *act)
273 Thread *t = get_thread(act);
274 ModelAction * prev = get_last_conflict(act);
278 Node * node = prev->get_node()->get_parent();
280 int low_tid, high_tid;
281 if (node->is_enabled(t)) {
282 low_tid = id_to_int(act->get_tid());
283 high_tid = low_tid+1;
286 high_tid = get_num_threads();
289 for(int i = low_tid; i < high_tid; i++) {
290 thread_id_t tid = int_to_id(i);
291 if (!node->is_enabled(tid))
294 /* Check if this has been explored already */
295 if (node->has_been_explored(tid))
298 /* See if fairness allows */
299 if (model->params.fairwindow != 0 && !node->has_priority(tid)) {
301 for(int t=0;t<node->get_num_threads();t++) {
302 thread_id_t tother=int_to_id(t);
303 if (node->is_enabled(tother) && node->has_priority(tother)) {
312 /* Cache the latest backtracking point */
313 if (!priv->next_backtrack || *prev > *priv->next_backtrack)
314 priv->next_backtrack = prev;
316 /* If this is a new backtracking point, mark the tree */
317 if (!node->set_backtrack(tid))
319 DEBUG("Setting backtrack: conflict = %d, instead tid = %d\n",
320 prev->get_tid(), t->get_id());
329 * Returns last backtracking point. The model checker will explore a different
330 * path for this point in the next execution.
331 * @return The ModelAction at which the next execution should diverge.
333 ModelAction * ModelChecker::get_next_backtrack()
335 ModelAction *next = priv->next_backtrack;
336 priv->next_backtrack = NULL;
341 * Processes a read or rmw model action.
342 * @param curr is the read model action to process.
343 * @param second_part_of_rmw is boolean that is true is this is the second action of a rmw.
344 * @return True if processing this read updates the mo_graph.
346 bool ModelChecker::process_read(ModelAction *curr, bool second_part_of_rmw)
349 bool updated = false;
351 const ModelAction *reads_from = curr->get_node()->get_read_from();
352 if (reads_from != NULL) {
353 mo_graph->startChanges();
355 value = reads_from->get_value();
356 bool r_status = false;
358 if (!second_part_of_rmw) {
359 check_recency(curr, reads_from);
360 r_status = r_modification_order(curr, reads_from);
364 if (!second_part_of_rmw&&!isfeasible()&&(curr->get_node()->increment_read_from()||curr->get_node()->increment_future_value())) {
365 mo_graph->rollbackChanges();
366 too_many_reads = false;
370 curr->read_from(reads_from);
371 mo_graph->commitChanges();
373 } else if (!second_part_of_rmw) {
374 /* Read from future value */
375 value = curr->get_node()->get_future_value();
376 modelclock_t expiration = curr->get_node()->get_future_value_expiration();
377 curr->read_from(NULL);
378 Promise *valuepromise = new Promise(curr, value, expiration);
379 promises->push_back(valuepromise);
381 get_thread(curr)->set_return_value(value);
387 * Processes a lock, trylock, or unlock model action. @param curr is
388 * the read model action to process.
390 * The try lock operation checks whether the lock is taken. If not,
391 * it falls to the normal lock operation case. If so, it returns
394 * The lock operation has already been checked that it is enabled, so
395 * it just grabs the lock and synchronizes with the previous unlock.
397 * The unlock operation has to re-enable all of the threads that are
398 * waiting on the lock.
400 * @return True if synchronization was updated; false otherwise
402 bool ModelChecker::process_mutex(ModelAction *curr) {
403 std::mutex *mutex = (std::mutex *)curr->get_location();
404 struct std::mutex_state *state = mutex->get_state();
405 switch (curr->get_type()) {
406 case ATOMIC_TRYLOCK: {
407 bool success = !state->islocked;
408 curr->set_try_lock(success);
410 get_thread(curr)->set_return_value(0);
413 get_thread(curr)->set_return_value(1);
415 //otherwise fall into the lock case
417 if (curr->get_cv()->getClock(state->alloc_tid) <= state->alloc_clock) {
418 printf("Lock access before initialization\n");
421 state->islocked = true;
422 ModelAction *unlock = get_last_unlock(curr);
423 //synchronize with the previous unlock statement
424 if (unlock != NULL) {
425 curr->synchronize_with(unlock);
430 case ATOMIC_UNLOCK: {
432 state->islocked = false;
433 //wake up the other threads
434 action_list_t *waiters = lock_waiters_map->get_safe_ptr(curr->get_location());
435 //activate all the waiting threads
436 for (action_list_t::iterator rit = waiters->begin(); rit != waiters->end(); rit++) {
437 scheduler->wake(get_thread(*rit));
449 * Process a write ModelAction
450 * @param curr The ModelAction to process
451 * @return True if the mo_graph was updated or promises were resolved
453 bool ModelChecker::process_write(ModelAction *curr)
455 bool updated_mod_order = w_modification_order(curr);
456 bool updated_promises = resolve_promises(curr);
458 if (promises->size() == 0) {
459 for (unsigned int i = 0; i < futurevalues->size(); i++) {
460 struct PendingFutureValue pfv = (*futurevalues)[i];
461 if (pfv.act->get_node()->add_future_value(pfv.value, pfv.expiration) &&
462 (!priv->next_backtrack || *pfv.act > *priv->next_backtrack))
463 priv->next_backtrack = pfv.act;
465 futurevalues->resize(0);
468 mo_graph->commitChanges();
469 get_thread(curr)->set_return_value(VALUE_NONE);
470 return updated_mod_order || updated_promises;
474 * @brief Process the current action for thread-related activity
476 * Performs current-action processing for a THREAD_* ModelAction. Proccesses
477 * may include setting Thread status, completing THREAD_FINISH/THREAD_JOIN
478 * synchronization, etc. This function is a no-op for non-THREAD actions
479 * (e.g., ATOMIC_{READ,WRITE,RMW,LOCK}, etc.)
481 * @param curr The current action
482 * @return True if synchronization was updated or a thread completed
484 bool ModelChecker::process_thread_action(ModelAction *curr)
486 bool updated = false;
488 switch (curr->get_type()) {
489 case THREAD_CREATE: {
490 Thread *th = (Thread *)curr->get_location();
491 th->set_creation(curr);
495 Thread *waiting, *blocking;
496 waiting = get_thread(curr);
497 blocking = (Thread *)curr->get_location();
498 if (!blocking->is_complete()) {
499 blocking->push_wait_list(curr);
500 scheduler->sleep(waiting);
502 do_complete_join(curr);
503 updated = true; /* trigger rel-seq checks */
507 case THREAD_FINISH: {
508 Thread *th = get_thread(curr);
509 while (!th->wait_list_empty()) {
510 ModelAction *act = th->pop_wait_list();
511 Thread *wake = get_thread(act);
512 scheduler->wake(wake);
513 do_complete_join(act);
514 updated = true; /* trigger rel-seq checks */
517 updated = true; /* trigger rel-seq checks */
521 check_promises(NULL, curr->get_cv());
532 * Initialize the current action by performing one or more of the following
533 * actions, as appropriate: merging RMWR and RMWC/RMW actions, stepping forward
534 * in the NodeStack, manipulating backtracking sets, allocating and
535 * initializing clock vectors, and computing the promises to fulfill.
537 * @param curr The current action, as passed from the user context; may be
538 * freed/invalidated after the execution of this function
539 * @return The current action, as processed by the ModelChecker. Is only the
540 * same as the parameter @a curr if this is a newly-explored action.
542 ModelAction * ModelChecker::initialize_curr_action(ModelAction *curr)
544 ModelAction *newcurr;
546 if (curr->is_rmwc() || curr->is_rmw()) {
547 newcurr = process_rmw(curr);
550 if (newcurr->is_rmw())
551 compute_promises(newcurr);
555 curr->set_seq_number(get_next_seq_num());
557 newcurr = node_stack->explore_action(curr, scheduler->get_enabled());
559 /* First restore type and order in case of RMW operation */
561 newcurr->copy_typeandorder(curr);
563 ASSERT(curr->get_location() == newcurr->get_location());
564 newcurr->copy_from_new(curr);
566 /* Discard duplicate ModelAction; use action from NodeStack */
569 /* Always compute new clock vector */
570 newcurr->create_cv(get_parent_action(newcurr->get_tid()));
574 /* Always compute new clock vector */
575 newcurr->create_cv(get_parent_action(newcurr->get_tid()));
577 * Perform one-time actions when pushing new ModelAction onto
580 if (newcurr->is_write())
581 compute_promises(newcurr);
587 * This method checks whether a model action is enabled at the given point.
588 * At this point, it checks whether a lock operation would be successful at this point.
589 * If not, it puts the thread in a waiter list.
590 * @param curr is the ModelAction to check whether it is enabled.
591 * @return a bool that indicates whether the action is enabled.
593 bool ModelChecker::check_action_enabled(ModelAction *curr) {
594 if (curr->is_lock()) {
595 std::mutex * lock = (std::mutex *)curr->get_location();
596 struct std::mutex_state * state = lock->get_state();
597 if (state->islocked) {
598 //Stick the action in the appropriate waiting queue
599 lock_waiters_map->get_safe_ptr(curr->get_location())->push_back(curr);
608 * This is the heart of the model checker routine. It performs model-checking
609 * actions corresponding to a given "current action." Among other processes, it
610 * calculates reads-from relationships, updates synchronization clock vectors,
611 * forms a memory_order constraints graph, and handles replay/backtrack
612 * execution when running permutations of previously-observed executions.
614 * @param curr The current action to process
615 * @return The next Thread that must be executed. May be NULL if ModelChecker
616 * makes no choice (e.g., according to replay execution, combining RMW actions,
619 Thread * ModelChecker::check_current_action(ModelAction *curr)
623 bool second_part_of_rmw = curr->is_rmwc() || curr->is_rmw();
625 if (!check_action_enabled(curr)) {
626 /* Make the execution look like we chose to run this action
627 * much later, when a lock is actually available to release */
628 get_current_thread()->set_pending(curr);
629 scheduler->sleep(get_current_thread());
630 return get_next_thread(NULL);
633 ModelAction *newcurr = initialize_curr_action(curr);
635 /* Add the action to lists before any other model-checking tasks */
636 if (!second_part_of_rmw)
637 add_action_to_lists(newcurr);
639 /* Build may_read_from set for newly-created actions */
640 if (curr == newcurr && curr->is_read())
641 build_reads_from_past(curr);
644 /* Initialize work_queue with the "current action" work */
645 work_queue_t work_queue(1, CheckCurrWorkEntry(curr));
647 while (!work_queue.empty()) {
648 WorkQueueEntry work = work_queue.front();
649 work_queue.pop_front();
652 case WORK_CHECK_CURR_ACTION: {
653 ModelAction *act = work.action;
654 bool update = false; /* update this location's release seq's */
655 bool update_all = false; /* update all release seq's */
657 if (process_thread_action(curr))
660 if (act->is_read() && process_read(act, second_part_of_rmw))
663 if (act->is_write() && process_write(act))
666 if (act->is_mutex_op() && process_mutex(act))
670 work_queue.push_back(CheckRelSeqWorkEntry(NULL));
672 work_queue.push_back(CheckRelSeqWorkEntry(act->get_location()));
675 case WORK_CHECK_RELEASE_SEQ:
676 resolve_release_sequences(work.location, &work_queue);
678 case WORK_CHECK_MO_EDGES: {
679 /** @todo Complete verification of work_queue */
680 ModelAction *act = work.action;
681 bool updated = false;
683 if (act->is_read()) {
684 const ModelAction *rf = act->get_reads_from();
685 if (rf != NULL && r_modification_order(act, rf))
688 if (act->is_write()) {
689 if (w_modification_order(act))
692 mo_graph->commitChanges();
695 work_queue.push_back(CheckRelSeqWorkEntry(act->get_location()));
704 check_curr_backtracking(curr);
706 set_backtracking(curr);
708 return get_next_thread(curr);
712 * Complete a THREAD_JOIN operation, by synchronizing with the THREAD_FINISH
713 * operation from the Thread it is joining with. Must be called after the
714 * completion of the Thread in question.
715 * @param join The THREAD_JOIN action
717 void ModelChecker::do_complete_join(ModelAction *join)
719 Thread *blocking = (Thread *)join->get_location();
720 ModelAction *act = get_last_action(blocking->get_id());
721 join->synchronize_with(act);
724 void ModelChecker::check_curr_backtracking(ModelAction * curr) {
725 Node *currnode = curr->get_node();
726 Node *parnode = currnode->get_parent();
728 if ((!parnode->backtrack_empty() ||
729 !currnode->read_from_empty() ||
730 !currnode->future_value_empty() ||
731 !currnode->promise_empty())
732 && (!priv->next_backtrack ||
733 *curr > *priv->next_backtrack)) {
734 priv->next_backtrack = curr;
738 bool ModelChecker::promises_expired() {
739 for (unsigned int promise_index = 0; promise_index < promises->size(); promise_index++) {
740 Promise *promise = (*promises)[promise_index];
741 if (promise->get_expiration()<priv->used_sequence_numbers) {
748 /** @return whether the current partial trace must be a prefix of a
750 bool ModelChecker::isfeasibleprefix() {
751 return promises->size() == 0 && pending_acq_rel_seq->size() == 0;
754 /** @return whether the current partial trace is feasible. */
755 bool ModelChecker::isfeasible() {
756 if (DBG_ENABLED() && mo_graph->checkForRMWViolation())
757 DEBUG("Infeasible: RMW violation\n");
759 return !mo_graph->checkForRMWViolation() && isfeasibleotherthanRMW();
762 /** @return whether the current partial trace is feasible other than
763 * multiple RMW reading from the same store. */
764 bool ModelChecker::isfeasibleotherthanRMW() {
766 if (mo_graph->checkForCycles())
767 DEBUG("Infeasible: modification order cycles\n");
769 DEBUG("Infeasible: failed promise\n");
771 DEBUG("Infeasible: too many reads\n");
772 if (bad_synchronization)
773 DEBUG("Infeasible: bad synchronization ordering\n");
774 if (promises_expired())
775 DEBUG("Infeasible: promises expired\n");
777 return !mo_graph->checkForCycles() && !failed_promise && !too_many_reads && !bad_synchronization && !promises_expired();
780 /** Returns whether the current completed trace is feasible. */
781 bool ModelChecker::isfinalfeasible() {
782 if (DBG_ENABLED() && promises->size() != 0)
783 DEBUG("Infeasible: unrevolved promises\n");
785 return isfeasible() && promises->size() == 0;
788 /** Close out a RMWR by converting previous RMWR into a RMW or READ. */
789 ModelAction * ModelChecker::process_rmw(ModelAction *act) {
790 int tid = id_to_int(act->get_tid());
791 ModelAction *lastread = get_last_action(tid);
792 lastread->process_rmw(act);
793 if (act->is_rmw() && lastread->get_reads_from()!=NULL) {
794 mo_graph->addRMWEdge(lastread->get_reads_from(), lastread);
795 mo_graph->commitChanges();
801 * Checks whether a thread has read from the same write for too many times
802 * without seeing the effects of a later write.
805 * 1) there must a different write that we could read from that would satisfy the modification order,
806 * 2) we must have read from the same value in excess of maxreads times, and
807 * 3) that other write must have been in the reads_from set for maxreads times.
809 * If so, we decide that the execution is no longer feasible.
811 void ModelChecker::check_recency(ModelAction *curr, const ModelAction *rf) {
812 if (params.maxreads != 0) {
814 if (curr->get_node()->get_read_from_size() <= 1)
816 //Must make sure that execution is currently feasible... We could
817 //accidentally clear by rolling back
820 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
821 int tid = id_to_int(curr->get_tid());
824 if ((int)thrd_lists->size() <= tid)
826 action_list_t *list = &(*thrd_lists)[tid];
828 action_list_t::reverse_iterator rit = list->rbegin();
830 for (; (*rit) != curr; rit++)
832 /* go past curr now */
835 action_list_t::reverse_iterator ritcopy = rit;
836 //See if we have enough reads from the same value
838 for (; count < params.maxreads; rit++,count++) {
839 if (rit==list->rend())
841 ModelAction *act = *rit;
845 if (act->get_reads_from() != rf)
847 if (act->get_node()->get_read_from_size() <= 1)
850 for (int i = 0; i<curr->get_node()->get_read_from_size(); i++) {
852 const ModelAction * write = curr->get_node()->get_read_from_at(i);
854 //Need a different write
858 /* Test to see whether this is a feasible write to read from*/
859 mo_graph->startChanges();
860 r_modification_order(curr, write);
861 bool feasiblereadfrom = isfeasible();
862 mo_graph->rollbackChanges();
864 if (!feasiblereadfrom)
868 bool feasiblewrite = true;
869 //new we need to see if this write works for everyone
871 for (int loop = count; loop>0; loop--,rit++) {
872 ModelAction *act=*rit;
873 bool foundvalue = false;
874 for (int j = 0; j<act->get_node()->get_read_from_size(); j++) {
875 if (act->get_node()->get_read_from_at(i)==write) {
881 feasiblewrite = false;
886 too_many_reads = true;
894 * Updates the mo_graph with the constraints imposed from the current
897 * Basic idea is the following: Go through each other thread and find
898 * the lastest action that happened before our read. Two cases:
900 * (1) The action is a write => that write must either occur before
901 * the write we read from or be the write we read from.
903 * (2) The action is a read => the write that that action read from
904 * must occur before the write we read from or be the same write.
906 * @param curr The current action. Must be a read.
907 * @param rf The action that curr reads from. Must be a write.
908 * @return True if modification order edges were added; false otherwise
910 bool ModelChecker::r_modification_order(ModelAction *curr, const ModelAction *rf)
912 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
915 ASSERT(curr->is_read());
917 /* Iterate over all threads */
918 for (i = 0; i < thrd_lists->size(); i++) {
919 /* Iterate over actions in thread, starting from most recent */
920 action_list_t *list = &(*thrd_lists)[i];
921 action_list_t::reverse_iterator rit;
922 for (rit = list->rbegin(); rit != list->rend(); rit++) {
923 ModelAction *act = *rit;
926 * Include at most one act per-thread that "happens
927 * before" curr. Don't consider reflexively.
929 if (act->happens_before(curr) && act != curr) {
930 if (act->is_write()) {
932 mo_graph->addEdge(act, rf);
936 const ModelAction *prevreadfrom = act->get_reads_from();
937 if (prevreadfrom != NULL && rf != prevreadfrom) {
938 mo_graph->addEdge(prevreadfrom, rf);
950 /** This method fixes up the modification order when we resolve a
951 * promises. The basic problem is that actions that occur after the
952 * read curr could not property add items to the modification order
955 * So for each thread, we find the earliest item that happens after
956 * the read curr. This is the item we have to fix up with additional
957 * constraints. If that action is write, we add a MO edge between
958 * the Action rf and that action. If the action is a read, we add a
959 * MO edge between the Action rf, and whatever the read accessed.
961 * @param curr is the read ModelAction that we are fixing up MO edges for.
962 * @param rf is the write ModelAction that curr reads from.
965 void ModelChecker::post_r_modification_order(ModelAction *curr, const ModelAction *rf)
967 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
969 ASSERT(curr->is_read());
971 /* Iterate over all threads */
972 for (i = 0; i < thrd_lists->size(); i++) {
973 /* Iterate over actions in thread, starting from most recent */
974 action_list_t *list = &(*thrd_lists)[i];
975 action_list_t::reverse_iterator rit;
976 ModelAction *lastact = NULL;
978 /* Find last action that happens after curr that is either not curr or a rmw */
979 for (rit = list->rbegin(); rit != list->rend(); rit++) {
980 ModelAction *act = *rit;
981 if (curr->happens_before(act) && (curr != act || curr->is_rmw())) {
987 /* Include at most one act per-thread that "happens before" curr */
988 if (lastact != NULL) {
990 //Case 1: The resolved read is a RMW, and we need to make sure
991 //that the write portion of the RMW mod order after rf
993 mo_graph->addEdge(rf, lastact);
994 } else if (lastact->is_read()) {
995 //Case 2: The resolved read is a normal read and the next
996 //operation is a read, and we need to make sure the value read
997 //is mod ordered after rf
999 const ModelAction *postreadfrom = lastact->get_reads_from();
1000 if (postreadfrom != NULL&&rf != postreadfrom)
1001 mo_graph->addEdge(rf, postreadfrom);
1003 //Case 3: The resolved read is a normal read and the next
1004 //operation is a write, and we need to make sure that the
1005 //write is mod ordered after rf
1007 mo_graph->addEdge(rf, lastact);
1015 * Updates the mo_graph with the constraints imposed from the current write.
1017 * Basic idea is the following: Go through each other thread and find
1018 * the lastest action that happened before our write. Two cases:
1020 * (1) The action is a write => that write must occur before
1023 * (2) The action is a read => the write that that action read from
1024 * must occur before the current write.
1026 * This method also handles two other issues:
1028 * (I) Sequential Consistency: Making sure that if the current write is
1029 * seq_cst, that it occurs after the previous seq_cst write.
1031 * (II) Sending the write back to non-synchronizing reads.
1033 * @param curr The current action. Must be a write.
1034 * @return True if modification order edges were added; false otherwise
1036 bool ModelChecker::w_modification_order(ModelAction *curr)
1038 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
1041 ASSERT(curr->is_write());
1043 if (curr->is_seqcst()) {
1044 /* We have to at least see the last sequentially consistent write,
1045 so we are initialized. */
1046 ModelAction *last_seq_cst = get_last_seq_cst(curr);
1047 if (last_seq_cst != NULL) {
1048 mo_graph->addEdge(last_seq_cst, curr);
1053 /* Iterate over all threads */
1054 for (i = 0; i < thrd_lists->size(); i++) {
1055 /* Iterate over actions in thread, starting from most recent */
1056 action_list_t *list = &(*thrd_lists)[i];
1057 action_list_t::reverse_iterator rit;
1058 for (rit = list->rbegin(); rit != list->rend(); rit++) {
1059 ModelAction *act = *rit;
1062 * If RMW, we already have all relevant edges,
1063 * so just skip to next thread.
1064 * If normal write, we need to look at earlier
1065 * actions, so continue processing list.
1074 * Include at most one act per-thread that "happens
1077 if (act->happens_before(curr)) {
1079 * Note: if act is RMW, just add edge:
1081 * The following edge should be handled elsewhere:
1082 * readfrom(act) --mo--> act
1084 if (act->is_write())
1085 mo_graph->addEdge(act, curr);
1086 else if (act->is_read() && act->get_reads_from() != NULL)
1087 mo_graph->addEdge(act->get_reads_from(), curr);
1090 } else if (act->is_read() && !act->is_synchronizing(curr) &&
1091 !act->same_thread(curr)) {
1092 /* We have an action that:
1093 (1) did not happen before us
1094 (2) is a read and we are a write
1095 (3) cannot synchronize with us
1096 (4) is in a different thread
1098 that read could potentially read from our write.
1100 if (thin_air_constraint_may_allow(curr, act)) {
1102 (curr->is_rmw() && act->is_rmw() && curr->get_reads_from() == act->get_reads_from() && isfeasibleotherthanRMW())) {
1103 struct PendingFutureValue pfv = {curr->get_value(),curr->get_seq_number()+params.maxfuturedelay,act};
1104 futurevalues->push_back(pfv);
1114 /** Arbitrary reads from the future are not allowed. Section 29.3
1115 * part 9 places some constraints. This method checks one result of constraint
1116 * constraint. Others require compiler support. */
1117 bool ModelChecker::thin_air_constraint_may_allow(const ModelAction * writer, const ModelAction *reader) {
1118 if (!writer->is_rmw())
1121 if (!reader->is_rmw())
1124 for (const ModelAction *search = writer->get_reads_from(); search != NULL; search = search->get_reads_from()) {
1125 if (search == reader)
1127 if (search->get_tid() == reader->get_tid() &&
1128 search->happens_before(reader))
1136 * Finds the head(s) of the release sequence(s) containing a given ModelAction.
1137 * The ModelAction under consideration is expected to be taking part in
1138 * release/acquire synchronization as an object of the "reads from" relation.
1139 * Note that this can only provide release sequence support for RMW chains
1140 * which do not read from the future, as those actions cannot be traced until
1141 * their "promise" is fulfilled. Similarly, we may not even establish the
1142 * presence of a release sequence with certainty, as some modification order
1143 * constraints may be decided further in the future. Thus, this function
1144 * "returns" two pieces of data: a pass-by-reference vector of @a release_heads
1145 * and a boolean representing certainty.
1147 * @todo Finish lazy updating, when promises are fulfilled in the future
1148 * @param rf The action that might be part of a release sequence. Must be a
1150 * @param release_heads A pass-by-reference style return parameter. After
1151 * execution of this function, release_heads will contain the heads of all the
1152 * relevant release sequences, if any exists
1153 * @return true, if the ModelChecker is certain that release_heads is complete;
1156 bool ModelChecker::release_seq_head(const ModelAction *rf, rel_heads_list_t *release_heads) const
1158 /* Only check for release sequences if there are no cycles */
1159 if (mo_graph->checkForCycles())
1163 ASSERT(rf->is_write());
1165 if (rf->is_release())
1166 release_heads->push_back(rf);
1168 break; /* End of RMW chain */
1170 /** @todo Need to be smarter here... In the linux lock
1171 * example, this will run to the beginning of the program for
1173 /** @todo The way to be smarter here is to keep going until 1
1174 * thread has a release preceded by an acquire and you've seen
1177 /* acq_rel RMW is a sufficient stopping condition */
1178 if (rf->is_acquire() && rf->is_release())
1179 return true; /* complete */
1181 rf = rf->get_reads_from();
1184 /* read from future: need to settle this later */
1185 return false; /* incomplete */
1188 if (rf->is_release())
1189 return true; /* complete */
1191 /* else relaxed write; check modification order for contiguous subsequence
1192 * -> rf must be same thread as release */
1193 int tid = id_to_int(rf->get_tid());
1194 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(rf->get_location());
1195 action_list_t *list = &(*thrd_lists)[tid];
1196 action_list_t::const_reverse_iterator rit;
1198 /* Find rf in the thread list */
1199 rit = std::find(list->rbegin(), list->rend(), rf);
1200 ASSERT(rit != list->rend());
1202 /* Find the last write/release */
1203 for (; rit != list->rend(); rit++)
1204 if ((*rit)->is_release())
1206 if (rit == list->rend()) {
1207 /* No write-release in this thread */
1208 return true; /* complete */
1210 ModelAction *release = *rit;
1212 ASSERT(rf->same_thread(release));
1214 bool certain = true;
1215 for (unsigned int i = 0; i < thrd_lists->size(); i++) {
1216 if (id_to_int(rf->get_tid()) == (int)i)
1218 list = &(*thrd_lists)[i];
1220 /* Can we ensure no future writes from this thread may break
1221 * the release seq? */
1222 bool future_ordered = false;
1224 ModelAction *last = get_last_action(int_to_id(i));
1225 if (last && (rf->happens_before(last) ||
1226 last->get_type() == THREAD_FINISH))
1227 future_ordered = true;
1229 for (rit = list->rbegin(); rit != list->rend(); rit++) {
1230 const ModelAction *act = *rit;
1231 /* Reach synchronization -> this thread is complete */
1232 if (act->happens_before(release))
1234 if (rf->happens_before(act)) {
1235 future_ordered = true;
1239 /* Only writes can break release sequences */
1240 if (!act->is_write())
1243 /* Check modification order */
1244 if (mo_graph->checkReachable(rf, act)) {
1245 /* rf --mo--> act */
1246 future_ordered = true;
1249 if (mo_graph->checkReachable(act, release))
1250 /* act --mo--> release */
1252 if (mo_graph->checkReachable(release, act) &&
1253 mo_graph->checkReachable(act, rf)) {
1254 /* release --mo-> act --mo--> rf */
1255 return true; /* complete */
1259 if (!future_ordered)
1260 return false; /* This thread is uncertain */
1264 release_heads->push_back(release);
1269 * A public interface for getting the release sequence head(s) with which a
1270 * given ModelAction must synchronize. This function only returns a non-empty
1271 * result when it can locate a release sequence head with certainty. Otherwise,
1272 * it may mark the internal state of the ModelChecker so that it will handle
1273 * the release sequence at a later time, causing @a act to update its
1274 * synchronization at some later point in execution.
1275 * @param act The 'acquire' action that may read from a release sequence
1276 * @param release_heads A pass-by-reference return parameter. Will be filled
1277 * with the head(s) of the release sequence(s), if they exists with certainty.
1278 * @see ModelChecker::release_seq_head
1280 void ModelChecker::get_release_seq_heads(ModelAction *act, rel_heads_list_t *release_heads)
1282 const ModelAction *rf = act->get_reads_from();
1284 complete = release_seq_head(rf, release_heads);
1286 /* add act to 'lazy checking' list */
1287 pending_acq_rel_seq->push_back(act);
1292 * Attempt to resolve all stashed operations that might synchronize with a
1293 * release sequence for a given location. This implements the "lazy" portion of
1294 * determining whether or not a release sequence was contiguous, since not all
1295 * modification order information is present at the time an action occurs.
1297 * @param location The location/object that should be checked for release
1298 * sequence resolutions. A NULL value means to check all locations.
1299 * @param work_queue The work queue to which to add work items as they are
1301 * @return True if any updates occurred (new synchronization, new mo_graph
1304 bool ModelChecker::resolve_release_sequences(void *location, work_queue_t *work_queue)
1306 bool updated = false;
1307 std::vector<ModelAction *>::iterator it = pending_acq_rel_seq->begin();
1308 while (it != pending_acq_rel_seq->end()) {
1309 ModelAction *act = *it;
1311 /* Only resolve sequences on the given location, if provided */
1312 if (location && act->get_location() != location) {
1317 const ModelAction *rf = act->get_reads_from();
1318 rel_heads_list_t release_heads;
1320 complete = release_seq_head(rf, &release_heads);
1321 for (unsigned int i = 0; i < release_heads.size(); i++) {
1322 if (!act->has_synchronized_with(release_heads[i])) {
1323 if (act->synchronize_with(release_heads[i]))
1326 set_bad_synchronization();
1331 /* Re-check all pending release sequences */
1332 work_queue->push_back(CheckRelSeqWorkEntry(NULL));
1333 /* Re-check act for mo_graph edges */
1334 work_queue->push_back(MOEdgeWorkEntry(act));
1336 /* propagate synchronization to later actions */
1337 action_list_t::reverse_iterator rit = action_trace->rbegin();
1338 for (; (*rit) != act; rit++) {
1339 ModelAction *propagate = *rit;
1340 if (act->happens_before(propagate)) {
1341 propagate->synchronize_with(act);
1342 /* Re-check 'propagate' for mo_graph edges */
1343 work_queue->push_back(MOEdgeWorkEntry(propagate));
1348 it = pending_acq_rel_seq->erase(it);
1353 // If we resolved promises or data races, see if we have realized a data race.
1354 if (checkDataRaces()) {
1362 * Performs various bookkeeping operations for the current ModelAction. For
1363 * instance, adds action to the per-object, per-thread action vector and to the
1364 * action trace list of all thread actions.
1366 * @param act is the ModelAction to add.
1368 void ModelChecker::add_action_to_lists(ModelAction *act)
1370 int tid = id_to_int(act->get_tid());
1371 action_trace->push_back(act);
1373 obj_map->get_safe_ptr(act->get_location())->push_back(act);
1375 std::vector<action_list_t> *vec = obj_thrd_map->get_safe_ptr(act->get_location());
1376 if (tid >= (int)vec->size())
1377 vec->resize(priv->next_thread_id);
1378 (*vec)[tid].push_back(act);
1380 if ((int)thrd_last_action->size() <= tid)
1381 thrd_last_action->resize(get_num_threads());
1382 (*thrd_last_action)[tid] = act;
1386 * @brief Get the last action performed by a particular Thread
1387 * @param tid The thread ID of the Thread in question
1388 * @return The last action in the thread
1390 ModelAction * ModelChecker::get_last_action(thread_id_t tid) const
1392 int threadid = id_to_int(tid);
1393 if (threadid < (int)thrd_last_action->size())
1394 return (*thrd_last_action)[id_to_int(tid)];
1400 * Gets the last memory_order_seq_cst write (in the total global sequence)
1401 * performed on a particular object (i.e., memory location), not including the
1403 * @param curr The current ModelAction; also denotes the object location to
1405 * @return The last seq_cst write
1407 ModelAction * ModelChecker::get_last_seq_cst(ModelAction *curr) const
1409 void *location = curr->get_location();
1410 action_list_t *list = obj_map->get_safe_ptr(location);
1411 /* Find: max({i in dom(S) | seq_cst(t_i) && isWrite(t_i) && samevar(t_i, t)}) */
1412 action_list_t::reverse_iterator rit;
1413 for (rit = list->rbegin(); rit != list->rend(); rit++)
1414 if ((*rit)->is_write() && (*rit)->is_seqcst() && (*rit) != curr)
1420 * Gets the last unlock operation performed on a particular mutex (i.e., memory
1421 * location). This function identifies the mutex according to the current
1422 * action, which is presumed to perform on the same mutex.
1423 * @param curr The current ModelAction; also denotes the object location to
1425 * @return The last unlock operation
1427 ModelAction * ModelChecker::get_last_unlock(ModelAction *curr) const
1429 void *location = curr->get_location();
1430 action_list_t *list = obj_map->get_safe_ptr(location);
1431 /* Find: max({i in dom(S) | isUnlock(t_i) && samevar(t_i, t)}) */
1432 action_list_t::reverse_iterator rit;
1433 for (rit = list->rbegin(); rit != list->rend(); rit++)
1434 if ((*rit)->is_unlock())
1439 ModelAction * ModelChecker::get_parent_action(thread_id_t tid)
1441 ModelAction *parent = get_last_action(tid);
1443 parent = get_thread(tid)->get_creation();
1448 * Returns the clock vector for a given thread.
1449 * @param tid The thread whose clock vector we want
1450 * @return Desired clock vector
1452 ClockVector * ModelChecker::get_cv(thread_id_t tid)
1454 return get_parent_action(tid)->get_cv();
1458 * Resolve a set of Promises with a current write. The set is provided in the
1459 * Node corresponding to @a write.
1460 * @param write The ModelAction that is fulfilling Promises
1461 * @return True if promises were resolved; false otherwise
1463 bool ModelChecker::resolve_promises(ModelAction *write)
1465 bool resolved = false;
1467 for (unsigned int i = 0, promise_index = 0; promise_index < promises->size(); i++) {
1468 Promise *promise = (*promises)[promise_index];
1469 if (write->get_node()->get_promise(i)) {
1470 ModelAction *read = promise->get_action();
1471 if (read->is_rmw()) {
1472 mo_graph->addRMWEdge(write, read);
1474 read->read_from(write);
1475 //First fix up the modification order for actions that happened
1477 r_modification_order(read, write);
1478 //Next fix up the modification order for actions that happened
1480 post_r_modification_order(read, write);
1481 //Make sure the promise's value matches the write's value
1482 ASSERT(promise->get_value() == write->get_value());
1485 promises->erase(promises->begin() + promise_index);
1494 * Compute the set of promises that could potentially be satisfied by this
1495 * action. Note that the set computation actually appears in the Node, not in
1497 * @param curr The ModelAction that may satisfy promises
1499 void ModelChecker::compute_promises(ModelAction *curr)
1501 for (unsigned int i = 0; i < promises->size(); i++) {
1502 Promise *promise = (*promises)[i];
1503 const ModelAction *act = promise->get_action();
1504 if (!act->happens_before(curr) &&
1506 !act->is_synchronizing(curr) &&
1507 !act->same_thread(curr) &&
1508 promise->get_value() == curr->get_value()) {
1509 curr->get_node()->set_promise(i);
1514 /** Checks promises in response to change in ClockVector Threads. */
1515 void ModelChecker::check_promises(ClockVector *old_cv, ClockVector *merge_cv)
1517 for (unsigned int i = 0; i < promises->size(); i++) {
1518 Promise *promise = (*promises)[i];
1519 const ModelAction *act = promise->get_action();
1520 if ((old_cv == NULL || !old_cv->synchronized_since(act)) &&
1521 merge_cv->synchronized_since(act)) {
1522 //This thread is no longer able to send values back to satisfy the promise
1523 int num_synchronized_threads = promise->increment_threads();
1524 if (num_synchronized_threads == get_num_threads()) {
1525 //Promise has failed
1526 failed_promise = true;
1534 * Build up an initial set of all past writes that this 'read' action may read
1535 * from. This set is determined by the clock vector's "happens before"
1537 * @param curr is the current ModelAction that we are exploring; it must be a
1540 void ModelChecker::build_reads_from_past(ModelAction *curr)
1542 std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
1544 ASSERT(curr->is_read());
1546 ModelAction *last_seq_cst = NULL;
1548 /* Track whether this object has been initialized */
1549 bool initialized = false;
1551 if (curr->is_seqcst()) {
1552 last_seq_cst = get_last_seq_cst(curr);
1553 /* We have to at least see the last sequentially consistent write,
1554 so we are initialized. */
1555 if (last_seq_cst != NULL)
1559 /* Iterate over all threads */
1560 for (i = 0; i < thrd_lists->size(); i++) {
1561 /* Iterate over actions in thread, starting from most recent */
1562 action_list_t *list = &(*thrd_lists)[i];
1563 action_list_t::reverse_iterator rit;
1564 for (rit = list->rbegin(); rit != list->rend(); rit++) {
1565 ModelAction *act = *rit;
1567 /* Only consider 'write' actions */
1568 if (!act->is_write() || act == curr)
1571 /* Don't consider more than one seq_cst write if we are a seq_cst read. */
1572 if (!curr->is_seqcst() || (!act->is_seqcst() && (last_seq_cst == NULL || !act->happens_before(last_seq_cst))) || act == last_seq_cst) {
1573 DEBUG("Adding action to may_read_from:\n");
1574 if (DBG_ENABLED()) {
1578 curr->get_node()->add_read_from(act);
1581 /* Include at most one act per-thread that "happens before" curr */
1582 if (act->happens_before(curr)) {
1590 /** @todo Need a more informative way of reporting errors. */
1591 printf("ERROR: may read from uninitialized atomic\n");
1594 if (DBG_ENABLED() || !initialized) {
1595 printf("Reached read action:\n");
1597 printf("Printing may_read_from\n");
1598 curr->get_node()->print_may_read_from();
1599 printf("End printing may_read_from\n");
1602 ASSERT(initialized);
1605 static void print_list(action_list_t *list)
1607 action_list_t::iterator it;
1609 printf("---------------------------------------------------------------------\n");
1612 for (it = list->begin(); it != list->end(); it++) {
1615 printf("---------------------------------------------------------------------\n");
1618 #if SUPPORT_MOD_ORDER_DUMP
1619 void ModelChecker::dumpGraph(char *filename) {
1621 sprintf(buffer, "%s.dot",filename);
1622 FILE *file=fopen(buffer, "w");
1623 fprintf(file, "digraph %s {\n",filename);
1624 mo_graph->dumpNodes(file);
1625 ModelAction ** thread_array=(ModelAction **)model_calloc(1, sizeof(ModelAction *)*get_num_threads());
1627 for (action_list_t::iterator it = action_trace->begin(); it != action_trace->end(); it++) {
1628 ModelAction *action=*it;
1629 if (action->is_read()) {
1630 fprintf(file, "N%u [label=\"%u, T%u\"];\n", action->get_seq_number(),action->get_seq_number(), action->get_tid());
1631 fprintf(file, "N%u -> N%u[label=\"rf\", color=red];\n", action->get_seq_number(), action->get_reads_from()->get_seq_number());
1633 if (thread_array[action->get_tid()] != NULL) {
1634 fprintf(file, "N%u -> N%u[label=\"sb\", color=blue];\n", thread_array[action->get_tid()]->get_seq_number(), action->get_seq_number());
1637 thread_array[action->get_tid()]=action;
1639 fprintf(file,"}\n");
1640 model_free(thread_array);
1645 void ModelChecker::print_summary()
1648 printf("Number of executions: %d\n", num_executions);
1649 printf("Number of feasible executions: %d\n", num_feasible_executions);
1650 printf("Total nodes created: %d\n", node_stack->get_total_nodes());
1652 #if SUPPORT_MOD_ORDER_DUMP
1654 char buffername[100];
1655 sprintf(buffername, "exec%04u", num_executions);
1656 mo_graph->dumpGraphToFile(buffername);
1657 sprintf(buffername, "graph%04u", num_executions);
1658 dumpGraph(buffername);
1661 if (!isfinalfeasible())
1662 printf("INFEASIBLE EXECUTION!\n");
1663 print_list(action_trace);
1668 * Add a Thread to the system for the first time. Should only be called once
1670 * @param t The Thread to add
1672 void ModelChecker::add_thread(Thread *t)
1674 thread_map->put(id_to_int(t->get_id()), t);
1675 scheduler->add_thread(t);
1679 * Removes a thread from the scheduler.
1680 * @param the thread to remove.
1682 void ModelChecker::remove_thread(Thread *t)
1684 scheduler->remove_thread(t);
1688 * Switch from a user-context to the "master thread" context (a.k.a. system
1689 * context). This switch is made with the intention of exploring a particular
1690 * model-checking action (described by a ModelAction object). Must be called
1691 * from a user-thread context.
1692 * @param act The current action that will be explored. Must not be NULL.
1693 * @return Return status from the 'swap' call (i.e., success/fail, 0/-1)
1695 int ModelChecker::switch_to_master(ModelAction *act)
1698 Thread *old = thread_current();
1699 set_current_action(act);
1700 old->set_state(THREAD_READY);
1701 return Thread::swap(old, &system_context);
1705 * Takes the next step in the execution, if possible.
1706 * @return Returns true (success) if a step was taken and false otherwise.
1708 bool ModelChecker::take_step() {
1712 Thread * curr = thread_current();
1714 if (curr->get_state() == THREAD_READY) {
1715 ASSERT(priv->current_action);
1717 priv->nextThread = check_current_action(priv->current_action);
1718 priv->current_action = NULL;
1720 if (curr->is_blocked() || curr->is_complete())
1721 scheduler->remove_thread(curr);
1726 Thread * next = scheduler->next_thread(priv->nextThread);
1728 /* Infeasible -> don't take any more steps */
1733 next->set_state(THREAD_RUNNING);
1734 DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
1736 /* next == NULL -> don't take any more steps */
1740 if ( next->get_pending() != NULL ) {
1741 //restart a pending action
1742 set_current_action(next->get_pending());
1743 next->set_pending(NULL);
1744 next->set_state(THREAD_READY);
1748 /* Return false only if swap fails with an error */
1749 return (Thread::swap(&system_context, next) == 0);
1752 /** Runs the current execution until threre are no more steps to take. */
1753 void ModelChecker::finish_execution() {
1756 while (take_step());