From 6c7d8fa10e321a1404e24311a5f16b94070e0d6b Mon Sep 17 00:00:00 2001
From: Brian Demsky <bdemsky@uci.edu>
Date: Fri, 27 Jul 2012 02:06:29 -0700
Subject: [PATCH] change test case to match nice one from spec...  it works. 
 :)

---
 userprog.c | 46 ++++++++++++++++++----------------------------
 1 file changed, 18 insertions(+), 28 deletions(-)

diff --git a/userprog.c b/userprog.c
index 6d8b57b..645dc30 100644
--- a/userprog.c
+++ b/userprog.c
@@ -1,48 +1,38 @@
 #include <stdio.h>
-#include <stdlib.h>
 
 #include "libthreads.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 ret;
-
-	store_32(&i, 10);
-	printf("load 32 yields: %d\n", load_32(&i));
-
-	for (i = 0; i < 2; i++) {
-		printf("Thread %d, loop %d\n", thrd_current(), i);
-		switch (i % 2) {
-		case 1:
-			ret = atomic_load(obj);
-			printf("Read value: %d\n", ret);
-			break;
-		case 0:
-			atomic_store(obj, i + 1);
-			printf("Write value: %d\n", i + 1);
-			break;
-		}
-	}
+	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 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;
-
-	obj = malloc(sizeof(*obj));
 
-	atomic_init(obj, 0);
+	atomic_init(&x, 0);
+	atomic_init(&y, 0);
 
 	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_create(&t1, (thrd_start_t)&a, NULL);
+	thrd_create(&t2, (thrd_start_t)&b, NULL);
 
 	thrd_join(t1);
 	thrd_join(t2);
-	free(obj);
 	printf("Thread %d is finished\n", thrd_current());
 }
-- 
2.34.1