include ../benchmarks.mk
TESTNAME = linuxrwlocks
-WILDCARD_TESTS = testcase1
+WILDCARD_TESTS = testcase1 testcase2 testcase_full
all: $(TESTNAME) $(WILDCARD_TESTS)
$(TESTNAME): $(TESTNAME).c $(TESTNAME).h
--- /dev/null
+We can run the testcase_full (a testcase that contains all the method calls of
+the data structure) to infer all the parameters in one file, but that takes a
+long time that is mainly spent on the model-checking for unknown wrong
+inferences. To make things faster, we could split the big testcase into small
+cases (plus corner cases) and then run each of them one after another.
+
+We ran testcase1 and then got inference result1.txt, then we ran testcase2 based
+on result1.txt, and we got result2.txt, which is the correct inference.
--- /dev/null
+Result 0:
+wildcard 3 -> memory_order_acquire
+wildcard 4 -> memory_order_relaxed
+wildcard 5 -> memory_order_relaxed
+wildcard 6 -> memory_order_acquire
+wildcard 7 -> memory_order_acquire
+wildcard 8 -> memory_order_relaxed
+wildcard 9 -> memory_order_relaxed
+wildcard 10 -> memory_order_acquire
+wildcard 13 -> memory_order_relaxed
+wildcard 14 -> memory_order_relaxed
+wildcard 15 -> memory_order_release
+wildcard 16 -> memory_order_release
--- /dev/null
+Result 0:
+wildcard 1 -> memory_order_relaxed
+wildcard 2 -> memory_order_relaxed
+wildcard 3 -> memory_order_acquire
+wildcard 4 -> memory_order_relaxed
+wildcard 5 -> memory_order_relaxed
+wildcard 6 -> memory_order_acquire
+wildcard 7 -> memory_order_acquire
+wildcard 8 -> memory_order_relaxed
+wildcard 9 -> memory_order_relaxed
+wildcard 10 -> memory_order_acquire
+wildcard 11 -> memory_order_acquire
+wildcard 12 -> memory_order_relaxed
+wildcard 13 -> memory_order_acquire
+wildcard 14 -> memory_order_relaxed
+wildcard 15 -> memory_order_release
+wildcard 16 -> memory_order_release
--- /dev/null
+Result 1:
+wildcard 1 -> memory_order_relaxed
+wildcard 3 -> memory_order_acquire
+wildcard 4 -> memory_order_relaxed
+wildcard 5 -> memory_order_relaxed
+wildcard 6 -> memory_order_acquire
+wildcard 7 -> memory_order_acquire
+wildcard 8 -> memory_order_relaxed
+wildcard 9 -> memory_order_relaxed
+wildcard 10 -> memory_order_acquire
+wildcard 11 -> memory_order_acquire
+wildcard 12 -> memory_order_relaxed
+wildcard 13 -> memory_order_relaxed
+wildcard 14 -> memory_order_relaxed
+wildcard 15 -> memory_order_release
+wildcard 16 -> memory_order_release
static void b(void *obj)
{
-
- write_lock(&mylock);
- atomic_store_explicit(&x, 16, relaxed);
- write_unlock(&mylock);
+ if (write_trylock(&mylock)) {
+ atomic_store_explicit(&x, 16, relaxed);
+ write_unlock(&mylock);
+ }
read_lock(&mylock);
atomic_load_explicit(&x, relaxed);
--- /dev/null
+#include <stdio.h>
+#include <threads.h>
+#include <stdatomic.h>
+#include "wildcard.h"
+
+#include "librace.h"
+#include "linuxrwlocks-wildcard.h"
+
+rwlock_t mylock;
+int shareddata;
+
+atomic_int x, y;
+
+static void a(void *obj)
+{
+ if (!write_can_lock(&mylock))
+ return;
+
+ if (write_trylock(&mylock)) {
+ atomic_store_explicit(&x, 17, relaxed);
+ write_unlock(&mylock);
+ }
+}
+
+static void b(void *obj)
+{
+ if (write_trylock(&mylock)) {
+ atomic_store_explicit(&x, 16, relaxed);
+ write_unlock(&mylock);
+ }
+
+ if (!read_can_lock(&mylock))
+ return;
+ if (read_trylock(&mylock)) {
+ atomic_load_explicit(&x, relaxed);
+ read_unlock(&mylock);
+ }
+}
+
+int user_main(int argc, char **argv)
+{
+ thrd_t t1, t2;
+ atomic_init(&mylock.lock, RW_LOCK_BIAS);
+ atomic_init(&x, 0);
+ atomic_init(&y, 0);
+
+ thrd_create(&t1, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
+
+ thrd_join(t1);
+ thrd_join(t2);
+
+ return 0;
+}
--- /dev/null
+#include <stdio.h>
+#include <threads.h>
+#include <stdatomic.h>
+#include "wildcard.h"
+
+#include "librace.h"
+#include "linuxrwlocks-wildcard.h"
+
+rwlock_t mylock;
+int shareddata;
+
+atomic_int x, y;
+
+static void a(void *obj)
+{
+ write_lock(&mylock);
+ atomic_store_explicit(&x, 17, relaxed);
+ write_unlock(&mylock);
+
+ if (!read_can_lock(&mylock))
+ return;
+ if (read_trylock(&mylock)) {
+ atomic_load_explicit(&x, relaxed);
+ read_unlock(&mylock);
+ }
+}
+
+static void b(void *obj)
+{
+
+ if (write_trylock(&mylock)) {
+ atomic_store_explicit(&x, 16, relaxed);
+ write_unlock(&mylock);
+ }
+
+ read_lock(&mylock);
+ atomic_load_explicit(&x, relaxed);
+ read_unlock(&mylock);
+}
+
+int user_main(int argc, char **argv)
+{
+ thrd_t t1, t2;
+ atomic_init(&mylock.lock, RW_LOCK_BIAS);
+ atomic_init(&x, 0);
+ atomic_init(&y, 0);
+
+ thrd_create(&t1, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
+
+ thrd_join(t1);
+ thrd_join(t2);
+
+ return 0;
+}