add support for pthread_create (in progress)
authorweiyu <weiyuluo1232@gmail.com>
Fri, 18 Jan 2019 03:06:30 +0000 (19:06 -0800)
committerweiyu <weiyuluo1232@gmail.com>
Fri, 18 Jan 2019 03:06:30 +0000 (19:06 -0800)
Makefile
model.cc
model.h
threads-model.h
threads.cc

index 3c51285..a7d2b52 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ OBJECTS := libthreads.o schedule.o model.o threads.o librace.o action.o \
           nodestack.o clockvector.o main.o snapshot-interface.o cyclegraph.o \
           datarace.o impatomic.o cmodelint.o \
           snapshot.o malloc.o mymemory.o common.o mutex.o promise.o conditionvariable.o \
-          context.o execution.o libannotate.o
+          context.o execution.o libannotate.o pthread.o
 
 CPPFLAGS += -Iinclude -I.
 LDFLAGS := -ldl -lrt -rdynamic
@@ -62,7 +62,8 @@ tags:
        ctags -R
 
 PHONY += tests
-tests: $(LIB_SO)       # $(MAKE) -C $(TESTS_DIR)
+tests: $(LIB_SO)
+       $(MAKE) -C $(TESTS_DIR)
 
 BENCH_DIR := benchmarks
 
index 8c384c1..ccc109a 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -518,7 +518,6 @@ void ModelChecker::run()
                                                        break;
                                                }
                                        } else if (act->get_type() == THREAD_CREATE || \
-                                                       act->get_type() == PTHREAD_CREATE || \ // WL
                                                        act->get_type() == THREAD_START || \
                                                        act->get_type() == THREAD_FINISH) {
                                                t = th;
@@ -543,7 +542,7 @@ void ModelChecker::run()
 
                has_next = next_execution();
                i++;
-       } while (i<1); // while (has_next);
+       } while (i<100); // while (has_next);
 
        execution->fixup_release_sequences();
 
diff --git a/model.h b/model.h
index 9448353..1d032e1 100644 (file)
--- a/model.h
+++ b/model.h
@@ -16,6 +16,8 @@
 #include "context.h"
 #include "params.h"
 
+#include <map>
+
 /* Forward declaration */
 class Node;
 class NodeStack;
@@ -78,6 +80,7 @@ public:
        void add_trace_analysis(TraceAnalysis *a) {     trace_analyses.push_back(a); }
        void set_inspect_plugin(TraceAnalysis *a) {     inspect_plugin=a;       }
        MEMALLOC
+       std::map<pthread_t, ModelAction*> pthread_map;
 private:
        /** Flag indicates whether to restart the model checker. */
        bool restart_flag;
index 11f2d54..f088bac 100644 (file)
@@ -43,6 +43,7 @@ public:
        Thread(thread_id_t tid);
        Thread(thread_id_t tid, thrd_t *t, void (*func)(void *), void *a, Thread *parent);
        Thread(thread_id_t tid, thrd_t *t, void *(*func)(void *), void *a, Thread *parent);
+
        ~Thread();
        void complete();
 
@@ -133,6 +134,7 @@ private:
 
        void (*start_routine)(void *);
        void *(*pstart_routine)(void *);
+
        void *arg;
        ucontext_t context;
        void *stack;
index 3d10f45..d7034e9 100644 (file)
@@ -51,10 +51,7 @@ void thread_startup()
        model->switch_to_master(new ModelAction(THREAD_START, std::memory_order_seq_cst, curr_thread));
 
        /* Call the actual thread function */
-       if ( !curr_thread->start_routine )
-               curr_thread->start_routine(curr_thread->arg);
-       else
-               curr_thread->pstart_routine(curr_thread->arg);
+       curr_thread->start_routine(curr_thread->arg);
        /* Finish thread properly */
        model->switch_to_master(new ModelAction(THREAD_FINISH, std::memory_order_seq_cst, curr_thread));
 }
@@ -172,17 +169,16 @@ 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;
+       // user_thread->priv = this; // WL
 }
 
-/** 
- * to be modified
- * Construct a new thread for pthread_create.
+/**
+ * Construct a new thread for pthread.
  * @param t The thread identifier of the newly created thread.
  * @param func The function that the thread will call.
  * @param a The parameter to pass to this function.
  */
-Thread::Thread(thread_id_t tid, thrd_t *t, void(*func)(void *), void *a, Thread *parent) :
+Thread::Thread(thread_id_t tid, thrd_t *t, void *(*func)(void *), void *a, Thread *parent) :
        parent(parent),
        creation(NULL),
        pending(NULL),
@@ -201,10 +197,9 @@ Thread::Thread(thread_id_t tid, thrd_t *t, void* (*func)(void *), void *a, Threa
        ret = create_context();
        if (ret)
                model_print("Error in create_context\n");
-
-       user_thread->priv = this;
 }
 
+
 /** Destructor */
 Thread::~Thread()
 {