X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=test%2Flitmus%2Fseq-lock.cc;fp=test%2Flitmus%2Fseq-lock.cc;h=447123cf18f80196e35664daaa041526d5184436;hb=1066ff319f565bb63268c1e6b6f48c114aac34b2;hp=0000000000000000000000000000000000000000;hpb=d8e5e19d215225df584752d5870e3fc0bbdcfbe3;p=model-checker.git diff --git a/test/litmus/seq-lock.cc b/test/litmus/seq-lock.cc new file mode 100644 index 0000000..447123c --- /dev/null +++ b/test/litmus/seq-lock.cc @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +std::atomic_int x; +std::atomic_int y; +std::atomic_int z; + +static int N = 1; + +static void a(void *obj) +{ + for (int i = 0; i < N; i++) { + x.store(2 * i + 1, std::memory_order_release); + y.store(i + 1, std::memory_order_release); + z.store(i + 1, std::memory_order_release); + x.store(2 * i + 2, std::memory_order_release); + } +} + +static void b(void *obj) +{ + printf("x: %d\n", x.load(std::memory_order_acquire)); + printf("y: %d\n", y.load(std::memory_order_acquire)); + printf("z: %d\n", z.load(std::memory_order_acquire)); + printf("x: %d\n", x.load(std::memory_order_acquire)); +} + +int user_main(int argc, char **argv) +{ + thrd_t t1, t2; + + if (argc > 1) + N = atoi(argv[1]); + + printf("N: %d\n", N); + + atomic_init(&x, 0); + atomic_init(&y, 0); + atomic_init(&z, 0); + + printf("Main thread: creating 2 threads\n"); + thrd_create(&t1, (thrd_start_t)&a, NULL); + thrd_create(&t2, (thrd_start_t)&b, NULL); + + thrd_join(t1); + thrd_join(t2); + printf("Main thread is finished\n"); + + return 0; +}