bool ModelAction::is_thread_join() const
{
- return type == THREAD_JOIN;
+ return type == THREAD_JOIN || type == PTHREAD_JOIN;
}
bool ModelAction::is_relseq_fixup() const
Thread * ModelAction::get_thread_operand() const
{
if (type == THREAD_CREATE) {
- /* THREAD_CREATE stores its (Thread *) in a thrd_t::priv */
- thrd_t *thrd = (thrd_t *)get_location();
- return thrd->priv;
+ /* thread_operand is set in execution.cc */
+ return thread_operand;
} else if (type == PTHREAD_CREATE) {
- // not implemented
- return NULL;
+ return thread_operand;
} else if (type == THREAD_JOIN) {
/* THREAD_JOIN uses (Thread *) for location */
return (Thread *)get_location();
} else if (type == PTHREAD_JOIN) {
- // WL: to be added (modified)
return (Thread *)get_location();
} else
return NULL;
{
const char *type_str = get_type_str(), *mo_str = get_mo_str();
- model_print("%-4d %-2d %-13s %7s %14p %-#18" PRIx64,
+ model_print("%-4d %-2d %-14s %7s %14p %-#18" PRIx64,
seq_number, id_to_int(tid), type_str, mo_str, location, get_return_value());
if (is_read()) {
if (reads_from)
bool may_read_from(const Promise *promise) const;
MEMALLOC
-// Added by WL
- void set_value(uint64_t val) {
- value = val;
- }
+ void set_value(uint64_t val) { value = val; }
+
+ /* to accomodate pthread create and join */
+ Thread * thread_operand;
+ void set_thread_operand(Thread *th) { thread_operand = th; }
private:
const char * get_type_str() const;
thrd_t *thrd = (thrd_t *)curr->get_location();
struct thread_params *params = (struct thread_params *)curr->get_value();
Thread *th = new Thread(get_next_id(), thrd, params->func, params->arg, get_thread(curr));
+ curr->set_thread_operand(th);
add_thread(th);
th->set_creation(curr);
/* Promises can be satisfied by children */
thrd_t *thrd = (thrd_t *)curr->get_location();
struct pthread_params *params = (struct pthread_params *)curr->get_value();
Thread *th = new Thread(get_next_id(), thrd, params->func, params->arg, get_thread(curr));
+ curr->set_thread_operand(th);
add_thread(th);
th->set_creation(curr);
/* Promises can be satisfied by children */
break;
}
case PTHREAD_JOIN: {
- break; // WL: to be add (modified)
Thread *blocking = curr->get_thread_operand();
ModelAction *act = get_last_action(blocking->get_id());
synchronize(act, curr);
updated = true; /* trigger rel-seq checks */
+ break; // WL: to be add (modified)
}
case THREAD_FINISH: {
} while (!should_terminate_execution());
has_next = next_execution();
+ pthread_map.clear();
i++;
} while (i<100); // while (has_next);
model->switch_to_master(new ModelAction(THREAD_START, std::memory_order_seq_cst, curr_thread));
/* Call the actual thread function */
- curr_thread->start_routine(curr_thread->arg);
+ if (curr_thread->start_routine != NULL) {
+ curr_thread->start_routine(curr_thread->arg);
+ } else if (curr_thread->pstart_routine != NULL) {
+ curr_thread->pstart_routine(curr_thread->arg);
+ }
/* Finish thread properly */
model->switch_to_master(new ModelAction(THREAD_FINISH, std::memory_order_seq_cst, curr_thread));
}
creation(NULL),
pending(NULL),
start_routine(func),
+ pstart_routine(NULL),
arg(a),
user_thread(t),
id(tid),
if (ret)
model_print("Error in create_context\n");
- // user_thread->priv = this; // WL
+ user_thread->priv = this; // WL
}
/**
if (pending->get_type() == THREAD_JOIN)
return pending->get_thread_operand();
- else if (pending->get_type() == PTHREAD_JOIN) {
- // WL: to be added
- }
+ else if (pending->get_type() == PTHREAD_JOIN)
+ return pending->get_thread_operand();
else if (pending->is_lock())
return (Thread *)pending->get_mutex()->get_state()->locked;
return NULL;