projects
/
model-checker-benchmarks.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e2354ef
)
mcs-lock: write proper driver
author
Brian Norris
<banorris@uci.edu>
Wed, 10 Oct 2012 18:11:55 +0000
(11:11 -0700)
committer
Brian Norris
<banorris@uci.edu>
Wed, 10 Oct 2012 18:11:55 +0000
(11:11 -0700)
mcs-lock/mcs-lock.cc
patch
|
blob
|
history
diff --git
a/mcs-lock/mcs-lock.cc
b/mcs-lock/mcs-lock.cc
index 6ba8f18a9a9bbca6762f65258377bf03330a4802..a541a2e4d919c0229234e5a38a2daba8ddef4bf1 100644
(file)
--- a/
mcs-lock/mcs-lock.cc
+++ b/
mcs-lock/mcs-lock.cc
@@
-3,12
+3,38
@@
#include "mcs-lock.h"
#include "mcs-lock.h"
-struct mcs_mutex mutex;
+/* For data race instrumentation */
+#include "librace.h"
+
+struct mcs_mutex *mutex;
+static uint32_t shared;
+
+void threadA(void *arg)
+{
+ mcs_mutex::guard g(mutex);
+ mutex->lock(&g);
+ printf("store: %d\n", 17);
+ store_32(&shared, 17);
+ mutex->unlock(&g);
+}
+
+void threadB(void *arg)
+{
+ mcs_mutex::guard g(mutex);
+ mutex->lock(&g);
+ printf("load: %u\n", load_32(&shared));
+ mutex->unlock(&g);
+}
int user_main(int argc, char **argv)
{
int user_main(int argc, char **argv)
{
- mcs_mutex::guard *g = new mcs_mutex::guard(&mutex);
- mutex.lock(g);
- mutex.unlock(g);
+ thrd_t A, B;
+
+ mutex = new mcs_mutex();
+
+ thrd_create(&A, &threadA, NULL);
+ thrd_create(&B, &threadB, NULL);
+ thrd_join(A);
+ thrd_join(B);
return 0;
}
return 0;
}