ModelChecker *model;
/** @brief Constructor */
-ModelChecker::ModelChecker()
- :
+ModelChecker::ModelChecker() :
/* Initialize default scheduler */
scheduler(new Scheduler()),
/* First thread created will have id INITIAL_THREAD_ID */
/** @brief Destructor */
ModelChecker::~ModelChecker()
{
- /* std::map<int, Thread *>::iterator it;
- for (it = thread_map->begin(); it != thread_map->end(); it++)
- delete (*it).second;*/
+ for (int i = 0; i < get_num_threads(); i++)
+ delete thread_map->get(i);
delete thread_map;
delete obj_thrd_map;
num_executions++;
- if (isfinalfeasible() || DBG_ENABLED())
- print_summary();
+ bool feasible = isfinalfeasible();
+ if (feasible || DBG_ENABLED())
+ print_summary(feasible);
if ((diverge = model->get_next_backtrack()) == NULL)
return false;
if (diverge==NULL) {
tmp->create_cv(get_parent_action(tmp->get_tid()));
}
-
+
delete curr;
curr = tmp;
} else {
if (!already_added)
add_action_to_lists(curr);
- /* Is there a better interface for setting the next thread rather
+ /** @todo Is there a better interface for setting the next thread rather
than this field/convoluted approach? Perhaps like just returning
it or something? */
Node *currnode = curr->get_node();
Node *parnode = currnode->get_parent();
- if (!parnode->backtrack_empty()||!currnode->read_from_empty()||!currnode->future_value_empty()||!currnode->promise_empty())
+ if (!parnode->backtrack_empty() || !currnode->read_from_empty() ||
+ !currnode->future_value_empty() || !currnode->promise_empty())
if (!next_backtrack || *curr > *next_backtrack)
next_backtrack = curr;
-
+
set_backtracking(curr);
}
if (act->happens_before(curr)) {
if (act->is_read()) {
const ModelAction * prevreadfrom=act->get_reads_from();
- if (rf!=prevreadfrom)
+ if (prevreadfrom!=NULL&&rf!=prevreadfrom)
cyclegraph->addEdge(rf, prevreadfrom);
} else if (rf!=act) {
cyclegraph->addEdge(rf, act);
}
}
+/** Updates the cyclegraph with the constraints imposed from the
+ * current read. */
+void ModelChecker::post_r_modification_order(ModelAction * curr, const ModelAction *rf) {
+ std::vector<action_list_t> *thrd_lists = obj_thrd_map->ensureptr(curr->get_location());
+ unsigned int i;
+ ASSERT(curr->is_read());
+
+ /* Iterate over all threads */
+ for (i = 0; i < thrd_lists->size(); i++) {
+ /* Iterate over actions in thread, starting from most recent */
+ action_list_t *list = &(*thrd_lists)[i];
+ action_list_t::reverse_iterator rit;
+ ModelAction *lastact=NULL;
+
+ /* Find last action that happens after curr */
+ for (rit = list->rbegin(); rit != list->rend(); rit++) {
+ ModelAction *act = *rit;
+ if (curr->happens_before(act)) {
+ lastact=act;
+ } else
+ break;
+ }
+
+ /* Include at most one act per-thread that "happens before" curr */
+ if (lastact!=NULL) {
+ if (lastact->is_read()) {
+ const ModelAction * postreadfrom=lastact->get_reads_from();
+ if (postreadfrom!=NULL&&rf!=postreadfrom)
+ cyclegraph->addEdge(postreadfrom, rf);
+ } else if (rf!=lastact) {
+ cyclegraph->addEdge(lastact, rf);
+ }
+ break;
+ }
+ }
+}
+
/**
* Updates the cyclegraph with the constraints imposed from the current write.
* @param curr The current action. Must be a write.
(1) did not happen before us
(2) is a read and we are a write
(3) cannot synchronize with us
- (4) is in a different thread
+ (4) is in a different thread
=>
that read could potentially read from our write.
*/
ModelAction * read=promise->get_action();
read->read_from(write);
r_modification_order(read, write);
+ post_r_modification_order(read, write);
promises->erase(promises->begin()+promise_index);
} else
promise_index++;
action_list_t::reverse_iterator rit;
for (rit = list->rbegin(); rit != list->rend(); rit++) {
ModelAction *act = *rit;
-
+
/* Only consider 'write' actions */
if (!act->is_write())
continue;
printf("---------------------------------------------------------------------\n");
}
-void ModelChecker::print_summary(void)
+void ModelChecker::print_summary(bool feasible)
{
printf("\n");
printf("Number of executions: %d\n", num_executions);
scheduler->print();
- if (!isfinalfeasible())
+ if (!feasible)
printf("INFEASIBLE EXECUTION!\n");
print_list(action_trace);
printf("\n");