From: Brian Norris Date: Thu, 26 Apr 2012 23:16:23 +0000 (-0700) Subject: libatomic: add atomic_init() X-Git-Tag: pldi2013~491 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fee76896120acbf7b5fa41fc99fca05c54b1f8da;p=model-checker.git libatomic: add atomic_init() --- diff --git a/libatomic.cc b/libatomic.cc index 6734148..f552d93 100644 --- a/libatomic.cc +++ b/libatomic.cc @@ -15,3 +15,8 @@ int atomic_load_explicit(struct atomic_object *obj, memory_order order) model->switch_to_master(new ModelAction(ATOMIC_READ, order, obj, VALUE_NONE)); return obj->value; } + +void atomic_init(struct atomic_object *obj, int value) +{ + obj->value = value; +} diff --git a/libatomic.h b/libatomic.h index 684b213..1806f21 100644 --- a/libatomic.h +++ b/libatomic.h @@ -24,6 +24,8 @@ extern "C" { int atomic_load_explicit(struct atomic_object *obj, memory_order order); #define atomic_load(A) atomic_load_explicit((A), memory_order_seq_cst) + void atomic_init(struct atomic_object *obj, int value); + #ifdef __cplusplus } #endif diff --git a/userprog.c b/userprog.c index bab9f98..2847c1a 100644 --- a/userprog.c +++ b/userprog.c @@ -28,6 +28,8 @@ void user_main() thrd_t t1, t2; atomic_int obj; + atomic_init(&obj, 0); + printf("Creating 2 threads\n"); thrd_create(&t1, (thrd_start_t)&a, &obj); thrd_create(&t2, (thrd_start_t)&a, &obj);