From 1a0114ccaf1f6a8dc1656589c6d733354fe310cd Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 30 May 2012 19:42:07 -0700 Subject: [PATCH] userprog: use atomics allocated on "heap" Just for kicks, since snapshotting is working properly. We might as well test this. --- userprog.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/userprog.c b/userprog.c index 2854ddc..33319b1 100644 --- a/userprog.c +++ b/userprog.c @@ -1,4 +1,5 @@ #include +#include #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()); } -- 2.34.1