6 #include "linuxrwlocks.h"
13 static void a(void *obj)
16 //atomic_store_explicit(&x, 17, memory_order_relaxed);
17 write_unlock(&mylock);
21 if (!write_can_lock(&mylock))
24 if (write_trylock(&mylock)) {
25 atomic_store_explicit(&x, 17, memory_order_relaxed);
26 write_unlock(&mylock);
31 static void b(void *obj)
33 //if (write_trylock(&mylock)) {
34 //atomic_store_explicit(&x, 16, memory_order_relaxed);
35 // write_unlock(&mylock);
39 //atomic_load_explicit(&x, memory_order_relaxed);
43 if (write_trylock(&mylock)) {
44 atomic_store_explicit(&x, 16, memory_order_relaxed);
45 write_unlock(&mylock);
48 if (!read_can_lock(&mylock))
50 if (read_trylock(&mylock)) {
51 atomic_load_explicit(&x, memory_order_relaxed);
57 int user_main(int argc, char **argv)
60 atomic_init(&mylock.lock, RW_LOCK_BIAS);
65 thrd_create(&t1, (thrd_start_t)&a, NULL);
66 thrd_create(&t2, (thrd_start_t)&b, NULL);