pthread join seems to be working
authorweiyu <weiyuluo1232@gmail.com>
Tue, 22 Jan 2019 21:58:14 +0000 (13:58 -0800)
committerweiyu <weiyuluo1232@gmail.com>
Tue, 22 Jan 2019 21:58:14 +0000 (13:58 -0800)
action.cc
action.h
execution.cc
model.cc
threads.cc

index ea4921050ee541575c65f43241211935268bfa36..359316d12a196e2c2d18c10e62685e1c1cf503a6 100644 (file)
--- a/action.cc
+++ b/action.cc
@@ -88,7 +88,7 @@ bool ModelAction::is_thread_start() const
 
 bool ModelAction::is_thread_join() const
 {
-       return type == THREAD_JOIN;
+       return type == THREAD_JOIN || type == PTHREAD_JOIN;
 }
 
 bool ModelAction::is_relseq_fixup() const
@@ -277,17 +277,14 @@ void ModelAction::copy_typeandorder(ModelAction * act)
 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;
@@ -597,7 +594,7 @@ void ModelAction::print() const
 {
        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)
index f7b66a89fc68482d5b2a0989ab1c88ec966ad5d7..f54c9d2aeb9b03d784d6c0762b037e765000d23b 100644 (file)
--- a/action.h
+++ b/action.h
@@ -189,10 +189,11 @@ public:
        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;
index 87e5425286e20253bce18d11f219631351b60819..fb72e8186aab8ad1feaf7837fbff1194b89bef6f 100644 (file)
@@ -949,6 +949,7 @@ bool ModelExecution::process_thread_action(ModelAction *curr)
                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 */
@@ -963,6 +964,7 @@ bool ModelExecution::process_thread_action(ModelAction *curr)
                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 */
@@ -981,11 +983,11 @@ bool ModelExecution::process_thread_action(ModelAction *curr)
                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: {
index 64bef579afd8b014ed00ad97f2178ad3685ddf67..9d147dfcc92e95ddd2e12284cbb486cb0018f430 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -542,6 +542,7 @@ void ModelChecker::run()
                } while (!should_terminate_execution());
 
                has_next = next_execution();
+               pthread_map.clear();
                i++;
        } while (i<100); // while (has_next);
 
index d7034e93e0d5d34afcfe0377dda9b4688dce91f5..77b13c69be0a9fb75f555edf3caa13e974ea5466 100644 (file)
@@ -51,7 +51,11 @@ void thread_startup()
        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));
 }
@@ -155,6 +159,7 @@ Thread::Thread(thread_id_t tid, thrd_t *t, void (*func)(void *), void *a, Thread
        creation(NULL),
        pending(NULL),
        start_routine(func),
+       pstart_routine(NULL),
        arg(a),
        user_thread(t),
        id(tid),
@@ -169,7 +174,7 @@ Thread::Thread(thread_id_t tid, thrd_t *t, void (*func)(void *), void *a, Thread
        if (ret)
                model_print("Error in create_context\n");
 
-       // user_thread->priv = this; // WL
+       user_thread->priv = this; // WL
 }
 
 /**
@@ -234,9 +239,8 @@ Thread * Thread::waiting_on() const
 
        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;