X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker-benchmarks.git;a=blobdiff_plain;f=mcs-lock%2Fmcs-lock.cc;h=ec0cc5df9d55c904d3a5cf9a677f42488371a7bb;hp=6ba8f18a9a9bbca6762f65258377bf03330a4802;hb=993e7e5146f39ff0ed459ac0a8bc30e7a0253156;hpb=e2354efc95efca2909429a2001cd910c9ce566fa diff --git a/mcs-lock/mcs-lock.cc b/mcs-lock/mcs-lock.cc index 6ba8f18..ec0cc5d 100644 --- a/mcs-lock/mcs-lock.cc +++ b/mcs-lock/mcs-lock.cc @@ -3,12 +3,41 @@ #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); + printf("store: %d\n", 17); + store_32(&shared, 17); + mutex->unlock(&g); + mutex->lock(&g); + printf("load: %u\n", load_32(&shared)); +} + +void threadB(void *arg) +{ + mcs_mutex::guard g(mutex); + printf("load: %u\n", load_32(&shared)); + mutex->unlock(&g); + mutex->lock(&g); + printf("store: %d\n", 17); + store_32(&shared, 17); +} 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; }