From dbcd23b77ba8e71d9b3fd35762ca307afa07bbac Mon Sep 17 00:00:00 2001 From: weiyu Date: Sat, 12 Dec 2020 16:00:19 -0800 Subject: [PATCH] Use the version of ms-queue modified by tsan11 --- .../ms-queue/Makefile | 6 ++--- .../ms-queue/main.cc | 22 +++++++++---------- .../ms-queue/my_queue.cc | 2 +- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/cdschecker_modified_benchmarks/ms-queue/Makefile b/cdschecker_modified_benchmarks/ms-queue/Makefile index f2a14ef..151ad71 100644 --- a/cdschecker_modified_benchmarks/ms-queue/Makefile +++ b/cdschecker_modified_benchmarks/ms-queue/Makefile @@ -5,15 +5,13 @@ TESTNAME = ms-queue HEADERS = my_queue.h OBJECTS = main.o my_queue.o -CXXFLAGS += -I /home/vagrant/c11tester/include - all: $(TESTNAME) $(TESTNAME): $(HEADERS) $(OBJECTS) - $(CC) -o $@ $(OBJECTS) $(CFLAGS) $(LDFLAGS) + $(CXX) -o $@ $(OBJECTS) $(CXXFLAGS) $(LDFLAGS) %.o: %.c - $(CC) -c -o $@ $(CFLAGS) + $(CXX) -c -o $@ $< $(CXXFLAGS) clean: rm -f $(TESTNAME) *.o diff --git a/cdschecker_modified_benchmarks/ms-queue/main.cc b/cdschecker_modified_benchmarks/ms-queue/main.cc index fc31f9c..d208414 100644 --- a/cdschecker_modified_benchmarks/ms-queue/main.cc +++ b/cdschecker_modified_benchmarks/ms-queue/main.cc @@ -1,13 +1,10 @@ #include #include -#include -//#include "cds_threads.h" +#include "cds_threads.h" #include "my_queue.h" #include "model-assert.h" -#define user_main main - static int procs = 4; static queue_t *queue; static thrd_t *threads; @@ -17,10 +14,10 @@ static int num_threads; int get_thread_num() { - thrd_t curr = thrd_current(); + //thrd_t curr = thrd_current(); int i; for (i = 0; i < num_threads; i++) - if (curr.priv == threads[i].priv) + if (std::this_thread::get_id() == threads[i].get_id()) return i; MODEL_ASSERT(0); return -1; @@ -30,6 +27,7 @@ bool succ1, succ2; static void main_task(void *param) { + unsigned int val; int pid = *((int *)param); if (!pid) { input[0] = 17; @@ -53,7 +51,7 @@ int user_main(int argc, char **argv) MODEL_ASSERT(queue); num_threads = procs; - threads = (thrd_t *)malloc(num_threads * sizeof(thrd_t)); + threads = (std::thread *)malloc(num_threads * sizeof(std::thread)); param = (int *)malloc(num_threads * sizeof(*param)); input = (unsigned *)calloc(num_threads, sizeof(*input)); output = (unsigned *)calloc(num_threads, sizeof(*output)); @@ -61,10 +59,11 @@ int user_main(int argc, char **argv) init_queue(queue, num_threads); for (i = 0; i < num_threads; i++) { param[i] = i; - thrd_create(&threads[i], main_task, ¶m[i]); + //threads[i] = std::thread(main_task, ¶m[i]); + new (&threads[i])std::thread(main_task, ¶m[i]); } for (i = 0; i < num_threads; i++) - thrd_join(threads[i]); + threads[i].join(); for (i = 0; i < num_threads; i++) { in_sum += input[i]; @@ -74,12 +73,11 @@ int user_main(int argc, char **argv) printf("input[%d] = %u\n", i, input[i]); for (i = 0; i < num_threads; i++) printf("output[%d] = %u\n", i, output[i]); -/* if (succ1 && succ2) MODEL_ASSERT(in_sum == out_sum); else - MODEL_ASSERT(false); -*/ + MODEL_ASSERT (false); + free(param); free(threads); free(queue); diff --git a/cdschecker_modified_benchmarks/ms-queue/my_queue.cc b/cdschecker_modified_benchmarks/ms-queue/my_queue.cc index d746bda..00af6d4 100644 --- a/cdschecker_modified_benchmarks/ms-queue/my_queue.cc +++ b/cdschecker_modified_benchmarks/ms-queue/my_queue.cc @@ -1,4 +1,4 @@ -#include +#include "cds_threads.h" #include #include "librace.h" #include "model-assert.h" -- 2.34.1