Add data structure benchmarks
[c11concurrency-benchmarks.git] / cdschecker_modified_benchmarks / mcs-lock / mcs-lock.cc
1 #include <stdio.h>
2 #include "cds_threads.h"
3
4 #include "mcs-lock.h"
5
6 /* For data race instrumentation */
7 #include "librace.h"
8
9 struct mcs_mutex *mutex;
10 static uint32_t shared;
11
12 void threadA(void *arg)
13 {
14 //      std::this_thread::sleep_for(std::chrono::milliseconds(10));
15         mcs_mutex::guard g(mutex);
16         printf("store: %d\n", 17);
17         store_32(&shared, 17);
18         mutex->unlock(&g);
19         mutex->lock(&g);
20         printf("load: %u\n", load_32(&shared));
21 }
22
23 void threadB(void *arg)
24 {
25 //      std::this_thread::sleep_for(std::chrono::milliseconds(10));
26         mcs_mutex::guard g(mutex);
27         printf("load: %u\n", load_32(&shared));
28         mutex->unlock(&g);
29         mutex->lock(&g);
30         printf("store: %d\n", 17);
31         store_32(&shared, 17);
32 }
33
34 int user_main(int argc, char **argv)
35 {
36         mutex = new mcs_mutex();
37
38         std::thread A(threadA, (void *)NULL);
39         std::thread B(threadB, (void *)NULL);
40         A.join();
41         B.join();
42         return 0;
43 }