change test case to match nice one from spec... it works. :)
[model-checker.git] / userprog.c
index c27c701591115f9ec903c6a771263bfc3b1bef98..645dc3095a366abeb79c976d6d456b6381760a17 100644 (file)
@@ -1,29 +1,38 @@
 #include <stdio.h>
 
 #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 i;
+       int r1=atomic_load_explicit(&y, memory_order_relaxed);
+       atomic_store_explicit(&x, r1, memory_order_relaxed);
+       printf("r1=%u\n",r1);
+}
 
-       for (i = 0; i < 10; i++) {
-               printf("Thread %d, loop %d\n", thread_current()->id, i);
-               if (i % 2)
-                       atomic_load(obj);
-       }
+static void b(void *obj)
+{
+       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()
 {
-       struct thread t1, t2;
-       atomic_int obj;
+       thrd_t t1, t2;
+
+       atomic_init(&x, 0);
+       atomic_init(&y, 0);
 
-       printf("%s() creating 2 threads\n", __func__);
-       thread_create(&t1, &a, &obj);
-       thread_create(&t2, &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);
 
-       thread_join(&t1);
-       thread_join(&t2);
-       printf("%s() is finished\n", __func__);
+       thrd_join(t1);
+       thrd_join(t2);
+       printf("Thread %d is finished\n", thrd_current());
 }