X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=blobdiff_plain;f=userprog.c;h=645dc3095a366abeb79c976d6d456b6381760a17;hp=2847c1af8e55d69acfe4d7cffc65924bd0b96f46;hb=6c7d8fa10e321a1404e24311a5f16b94070e0d6b;hpb=fee76896120acbf7b5fa41fc99fca05c54b1f8da diff --git a/userprog.c b/userprog.c index 2847c1a..645dc30 100644 --- a/userprog.c +++ b/userprog.c @@ -1,40 +1,38 @@ #include #include "libthreads.h" -#include "libatomic.h" +#include "librace.h" +#include "stdatomic.h" -static void a(atomic_int *obj) +atomic_int x; +atomic_int y; + +static void a(void *obj) +{ + int r1=atomic_load_explicit(&y, memory_order_relaxed); + atomic_store_explicit(&x, r1, memory_order_relaxed); + printf("r1=%u\n",r1); +} + +static void b(void *obj) { - int i; - int ret; - - for (i = 0; i < 10; i++) { - printf("Thread %d, loop %d\n", thrd_current(), i); - switch (i % 4) { - case 1: - ret = atomic_load(obj); - printf("Read value: %d\n", ret); - break; - case 3: - atomic_store(obj, i); - printf("Write value: %d\n", i); - break; - } - } + int r2=atomic_load_explicit(&x, memory_order_relaxed); + atomic_store_explicit(&y, 42, memory_order_relaxed); + printf("r2=%u\n",r2); } void user_main() { thrd_t t1, t2; - atomic_int obj; - atomic_init(&obj, 0); + atomic_init(&x, 0); + atomic_init(&y, 0); - printf("Creating 2 threads\n"); - thrd_create(&t1, (thrd_start_t)&a, &obj); - thrd_create(&t2, (thrd_start_t)&a, &obj); + printf("Thread %d: creating 2 threads\n", thrd_current()); + thrd_create(&t1, (thrd_start_t)&a, NULL); + thrd_create(&t2, (thrd_start_t)&b, NULL); thrd_join(t1); thrd_join(t2); - printf("Thread is finished\n"); + printf("Thread %d is finished\n", thrd_current()); }