userprog: use atomics allocated on "heap"
[model-checker.git] / userprog.c
index 2854ddc4a6b73bdf366b63262ed63ff3c8911eff..33319b1ce873c891b4bce429790196280b3acc12 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <stdlib.h>
 
 #include "libthreads.h"
 #include "libatomic.h"
@@ -30,15 +31,18 @@ static void a(atomic_int *obj)
 void user_main()
 {
        thrd_t t1, t2;
-       atomic_int obj;
+       atomic_int *obj;
 
-       atomic_init(&obj, 0);
+       obj = malloc(sizeof(*obj));
+
+       atomic_init(obj, 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, obj);
+       thrd_create(&t2, (thrd_start_t)&a, obj);
 
        thrd_join(t1);
        thrd_join(t2);
+       free(obj);
        printf("Thread %d is finished\n", thrd_current());
 }