ms-queue: remove more externs and unintended shared data
[model-checker-benchmarks.git] / mcs-lock / mcs-lock.cc
1 #include <stdio.h>
2 #include <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         mcs_mutex::guard g(mutex);
15         printf("store: %d\n", 17);
16         store_32(&shared, 17);
17         mutex->unlock(&g);
18         mutex->lock(&g);
19         printf("load: %u\n", load_32(&shared));
20 }
21
22 void threadB(void *arg)
23 {
24         mcs_mutex::guard g(mutex);
25         printf("load: %u\n", load_32(&shared));
26         mutex->unlock(&g);
27         mutex->lock(&g);
28         printf("store: %d\n", 17);
29         store_32(&shared, 17);
30 }
31
32 int user_main(int argc, char **argv)
33 {
34         thrd_t A, B;
35
36         mutex = new mcs_mutex();
37
38         thrd_create(&A, &threadA, NULL);
39         thrd_create(&B, &threadB, NULL);
40         thrd_join(A);
41         thrd_join(B);
42         return 0;
43 }