save
authorPeizhao Ou <peizhaoo@uci.edu>
Wed, 19 Mar 2014 03:51:08 +0000 (20:51 -0700)
committerPeizhao Ou <peizhaoo@uci.edu>
Wed, 19 Mar 2014 03:51:08 +0000 (20:51 -0700)
benchmark/linuxrwlocks/linuxrwlocks.c
benchmark/read-copy-update/rcu.cc

index c7ef94c..eaae816 100644 (file)
@@ -293,16 +293,36 @@ static void a(void *obj)
        for(i = 0; i < 2; i++) {
                if ((i % 2) == 0) {
                        read_lock(&mylock);
-                       load_32(&shareddata);
+                       //load_32(&shareddata);
+                       printf("%d\n", shareddata);
                        read_unlock(&mylock);
                } else {
                        write_lock(&mylock);
-                       store_32(&shareddata,(unsigned int)i);
+                       //store_32(&shareddata,(unsigned int)i);
+                       shareddata = 47;
                        write_unlock(&mylock);
                }
        }
 }
 
+static void b(void *obj)
+{
+       int i;
+       for(i = 0; i < 2; i++) {
+               if ((i % 2) == 0) {
+                       if (read_trylock(&mylock) == 1) {
+                               printf("%d\n", shareddata);
+                               read_unlock(&mylock);
+                       }
+               } else {
+                       if (write_trylock(&mylock) == 1) {
+                               shareddata = 47;
+                               write_unlock(&mylock);
+                       }
+               }
+       }
+}
+
 int user_main(int argc, char **argv)
 {
        /**
@@ -314,7 +334,7 @@ int user_main(int argc, char **argv)
        atomic_init(&mylock.lock, RW_LOCK_BIAS);
 
        thrd_create(&t1, (thrd_start_t)&a, NULL);
-       thrd_create(&t2, (thrd_start_t)&a, NULL);
+       thrd_create(&t2, (thrd_start_t)&b, NULL);
 
        thrd_join(t1);
        thrd_join(t2);
index 6f79126..3b49559 100644 (file)
@@ -87,7 +87,7 @@ void write(Data *new_data) {
        bool succ = false;
        do {
                succ = data.compare_exchange_strong(prev, new_data,
-                       memory_order_release, memory_order_relaxed); 
+                       memory_order_acq_rel, memory_order_relaxed); 
                /**
                        @Begin
                        @Commit_point_define_check: succ