userprog: separate test 'program' out to userprog.c
[c11tester.git] / userprog.c
diff --git a/userprog.c b/userprog.c
new file mode 100644 (file)
index 0000000..8358a58
--- /dev/null
@@ -0,0 +1,29 @@
+#include <stdio.h>
+
+#include "libthreads.h"
+#include "libatomic.h"
+
+static void a(atomic_int *obj)
+{
+       int i;
+
+       for (i = 0; i < 10; i++) {
+               printf("Thread %d, loop %d\n", thread_current()->index, i);
+               if (i % 2)
+                       atomic_load(obj);
+       }
+}
+
+void user_main()
+{
+       struct thread t1, t2;
+       atomic_int obj;
+
+       printf("%s() creating 2 threads\n", __func__);
+       thread_create(&t1, &a, &obj);
+       thread_create(&t2, &a, &obj);
+
+       thread_join(&t1);
+       thread_join(&t2);
+       printf("%s() is finished\n", __func__);
+}