3 * @brief Independent read and independent write test
11 #include "model-assert.h"
16 int r1, r2, r3, r4; /* "local" variables */
18 static void a(void *obj)
20 x.store(1, memory_order_seq_cst);
23 static void b(void *obj)
25 y.store(1, memory_order_seq_cst);
28 static void c(void *obj)
30 r1 = x.load(memory_order_acquire);
31 r2 = y.load(memory_order_seq_cst);
34 static void d(void *obj)
36 r3 = y.load(memory_order_acquire);
37 r4 = x.load(memory_order_seq_cst);
41 int user_main(int argc, char **argv)
43 thrd_t t1, t2, t3, t4;
48 printf("Main thread: creating 4 threads\n");
49 thrd_create(&t1, (thrd_start_t)&a, NULL);
50 thrd_create(&t2, (thrd_start_t)&b, NULL);
51 thrd_create(&t3, (thrd_start_t)&c, NULL);
52 thrd_create(&t4, (thrd_start_t)&d, NULL);
58 printf("Main thread is finished\n");
61 * This condition should not be hit if the execution is SC */
62 bool sc = (r1 == 1 && r2 == 0 && r3 == 1 && r4 == 0);
63 printf("r1 = %d, r2 = %d, r3 = %d and r4 = %d\n", r1, r2, r3, r4);