userprog: use both atomic loads and stores
authorBrian Norris <banorris@uci.edu>
Tue, 10 Apr 2012 22:19:29 +0000 (15:19 -0700)
committerBrian Norris <banorris@uci.edu>
Tue, 10 Apr 2012 22:50:15 +0000 (15:50 -0700)
(Meaningless change to 'user' program; just for testing purposes)

userprog.c

index 1837fc98c68d2a995d664dee2408fa05bc0d2c33..d24af11ce830556bf3b55b7423036f604fc31354 100644 (file)
@@ -9,8 +9,14 @@ static void a(atomic_int *obj)
 
        for (i = 0; i < 10; i++) {
                printf("Thread %d, loop %d\n", thread_current()->id, i);
-               if (i % 2)
+               switch (i % 4) {
+               case 1:
                        atomic_load(obj);
+                       break;
+               case 3:
+                       atomic_store(obj, i);
+                       break;
+               }
        }
 }
 
@@ -19,11 +25,11 @@ void user_main()
        struct thread t1, t2;
        atomic_int obj;
 
-       printf("%s() creating 2 threads\n", __func__);
+       printf("Thread %d creating 2 threads\n", thread_current()->id);
        thread_create(&t1, (void (*)())&a, &obj);
        thread_create(&t2, (void (*)())&a, &obj);
 
        thread_join(&t1);
        thread_join(&t2);
-       printf("%s() is finished\n", __func__);
+       printf("Thread %d is finished\n", thread_current()->id);
 }