From 92db01802459e4913d32683c27e8b5cea2d9c2b2 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 22 Jan 2013 11:08:06 -0800 Subject: [PATCH] test: rmwprog: support command-line argument This test can easily be extended to allow more than 2 atomic increments per thread. For instance, it's interesting to see the model-checker behavior for 4 increments per thread. Now, you can do this with a simple numeric command-line argument that gets passed to the user program. Example - run rmwprog with 4 increments per thread, viewing the execution traces verbosely: ./run.sh test/rmwprog.o -v -- 4 --- test/rmwprog.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/rmwprog.c b/test/rmwprog.c index feac776..57ab544 100644 --- a/test/rmwprog.c +++ b/test/rmwprog.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,17 +6,22 @@ #include "librace.h" atomic_int x; +static int N = 2; static void a(void *obj) { - atomic_fetch_add_explicit(&x, 1, memory_order_relaxed); - atomic_fetch_add_explicit(&x, 1, memory_order_relaxed); + int i; + for (i = 0; i < N; i++) + atomic_fetch_add_explicit(&x, 1, memory_order_relaxed); } int user_main(int argc, char **argv) { thrd_t t1, t2; + if (argc > 1) + N = atoi(argv[1]); + atomic_init(&x, 0); thrd_create(&t1, (thrd_start_t)&a, NULL); thrd_create(&t2, (thrd_start_t)&a, NULL); -- 2.34.1