order(order),
location(loc),
value(value),
+ reads_from(NULL),
cv(NULL)
{
Thread *t = thread_current();
// Different locations commute
if (!same_var(act))
return false;
-
+
// Explore interleavings of seqcst writes to guarantee total order
// of seq_cst operations that don't commute
if (is_write() && is_seqcst() && act->is_write() && act->is_seqcst())
ASSERT(cv);
if (act->is_release() && this->is_acquire())
cv->merge(act->cv);
+ reads_from = act;
value = act->value;
}
case THREAD_CREATE:
type_str = "thread create";
break;
+ case THREAD_START:
+ type_str = "thread start";
+ break;
case THREAD_YIELD:
type_str = "thread yield";
break;
type_str = "unknown type";
}
- printf("(%3d) Thread: %-2d Action: %-13s MO: %d Loc: %14p Value: %d",
+ printf("(%3d) Thread: %-2d Action: %-13s MO: %d Loc: %14p Value: %-4d",
seq_number, id_to_int(tid), type_str, order, location, value);
+ if (reads_from)
+ printf(" Rf: %d", reads_from->get_seq_number());
if (cv) {
printf("\t");
cv->print();
* ModelAction */
typedef enum action_type {
THREAD_CREATE, /**< A thread creation action */
+ THREAD_START, /**< First action in each thread */
THREAD_YIELD, /**< A thread yield action */
THREAD_JOIN, /**< A thread join action */
ATOMIC_READ, /**< An atomic read action */
void * get_location() const { return location; }
modelclock_t get_seq_number() const { return seq_number; }
int get_value() const { return value; }
+ const ModelAction * get_reads_from() const { return reads_from; }
Node * get_node() const { return node; }
void set_node(Node *n) { node = n; }
- void set_value(int val) { value = val; }
bool is_read() const;
bool is_write() const;
/** The thread id that performed this action. */
thread_id_t tid;
-
+
/** The value read or written (if RMW, then the value written). This
* should probably be something longer. */
int value;
+ /** The action that this action reads from. Only valid for reads */
+ const ModelAction *reads_from;
+
/** A back reference to a Node in NodeStack, if this ModelAction is
* saved on the NodeStack. */
Node *node;
-
+
modelclock_t seq_number;
/** The clock vector stored with this action; only needed if this
}
/**
- * Merge a clock vector into this vector, using a pairwise vector. The
+ * Merge a clock vector into this vector, using a pairwise comparison. The
* resulting vector length will be the maximum length of the two being merged.
* @param cv is the ClockVector being merged into this vector.
*/
-void ClockVector::merge(ClockVector *cv)
+void ClockVector::merge(const ClockVector *cv)
{
modelclock_t *clk = clock;
bool resize = false;
return false;
}
- /**
+ /**
* Gets the clock corresponding to a given thread id from the clock
* vector. */
#include "common.h"
#include "threads.h"
+ #include "datarace.h"
+
/* global "model" object */
#include "model.h"
#include "snapshot-interface.h"
/** The real_main function contains the main model checking loop. */
-void real_main() {
+static void real_main() {
thrd_t user_thread;
ucontext_t main_context;
+ //Initialize race detector
+ initRaceDetector();
+
//Create the singleton SnapshotStack object
snapshotObject = new SnapshotStack();
set_backtracking(curr);
add_action_to_lists(curr);
+
+ /* Assign reads_from values */
+ /* TODO: perform release/acquire synchronization here; include
+ * reads_from as ModelAction member? */
+ Thread *th = get_thread(curr->get_tid());
+ int value = VALUE_NONE;
+ if (curr->is_read()) {
+ const ModelAction *reads_from = curr->get_node()->get_next_read_from();
+ value = reads_from->get_value();
+ /* Assign reads_from, perform release/acquire synchronization */
+ curr->read_from(reads_from);
+ }
+ th->set_return_value(value);
}
/**
*/
void ModelChecker::add_action_to_lists(ModelAction *act)
{
+ int tid = id_to_int(act->get_tid());
action_trace->push_back(act);
std::vector<action_list_t> *vec = &(*obj_thrd_map)[act->get_location()];
- if (id_to_int(act->get_tid()) >= (int)vec->size())
+ if (tid >= (int)vec->size())
vec->resize(next_thread_id);
- (*vec)[id_to_int(act->get_tid())].push_back(act);
+ (*vec)[tid].push_back(act);
- (*thrd_last_action)[id_to_int(act->get_tid())] = act;
+ if ((int)thrd_last_action->size() <= tid)
+ thrd_last_action->resize(get_num_threads());
+ (*thrd_last_action)[tid] = act;
}
ModelAction * ModelChecker::get_last_action(thread_id_t tid)
return parent;
}
+ ClockVector * ModelChecker::get_cv(thread_id_t tid) {
+ return get_parent_action(tid)->get_cv();
+ }
+
/**
* Build up an initial set of all past writes that this 'read' action may read
* from. This set is determined by the clock vector's "happens before"