Adding STL stuff and operator news of snapshot to model-checker. Need to actuallly...
[model-checker.git] / userprog.c
index 1837fc98c68d2a995d664dee2408fa05bc0d2c33..5598bfb4b7b6558496b2ea5383d90500d8e014a2 100644 (file)
@@ -6,24 +6,35 @@
 static void a(atomic_int *obj)
 {
        int i;
+       int ret;
 
-       for (i = 0; i < 10; i++) {
-               printf("Thread %d, loop %d\n", thread_current()->id, i);
-               if (i % 2)
-                       atomic_load(obj);
+       for (i = 0; i < 7; i++) {
+               printf("Thread %d, loop %d\n", thrd_current(), i);
+               switch (i  ) {
+               case 1:
+                       ret = atomic_load(obj);
+                       printf("Read value: %d\n", ret);
+                       break;
+               case 0:
+                       atomic_store(obj, i);
+                       printf("Write value: %d\n", i);
+                       break;
+               }
        }
 }
 
 void user_main()
 {
-       struct thread t1, t2;
+       thrd_t t1, t2;
        atomic_int obj;
 
-       printf("%s() creating 2 threads\n", __func__);
-       thread_create(&t1, (void (*)())&a, &obj);
-       thread_create(&t2, (void (*)())&a, &obj);
+       atomic_init(&obj, 0);
 
-       thread_join(&t1);
-       thread_join(&t2);
-       printf("%s() is finished\n", __func__);
+       printf("Thread %d: creating 2 threads\n", thrd_current());
+       thrd_create(&t1, (thrd_start_t)&a, &obj);
+       thrd_create(&t2, (thrd_start_t)&a, &obj);
+
+       thrd_join(t1);
+       thrd_join(t2);
+       printf("Thread %d is finished\n", thrd_current());
 }