--- /dev/null
+BASE = ../..
+
+include $(BASE)/common.mk
+
+CPPFLAGS += -I$(BASE) -I$(BASE)/include
+
+SRCS = $(wildcard *.c)
+CPSRCS = $(wildcard *.cc)
+OBJS = $(patsubst %.c,%.o,$(SRCS)) $(patsubst %.cc,%.o,$(CPSRCS))
+
+all: $(OBJS)
+
+%.o: %.c
+ $(CC) -o $@ $< $(CPPFLAGS) -L$(BASE) -l$(LIB_NAME)
+
+%.o: %.cc
+ $(CXX) -o $@ $< $(CPPFLAGS) -L$(BASE) -l$(LIB_NAME)
+
+clean::
+ rm -f *.o
--- /dev/null
+#include <stdio.h>
+#include <threads.h>
+#include <atomic>
+
+std::atomic_int x;
+std::atomic_int y;
+
+static void a(void *obj)
+{
+ x.store(1, std::memory_order_release);
+}
+
+static void b(void *obj)
+{
+ y.store(1, std::memory_order_release);
+}
+
+static void c(void *obj)
+{
+ printf("x1: %d\n", x.load(std::memory_order_relaxed));
+ printf("y1: %d\n", y.load(std::memory_order_relaxed));
+}
+
+static void d(void *obj)
+{
+ printf("y2: %d\n", y.load(std::memory_order_relaxed));
+ printf("x2: %d\n", x.load(std::memory_order_relaxed));
+}
+
+int user_main(int argc, char **argv)
+{
+ thrd_t t1, t2, t3, t4;
+
+ atomic_init(&x, 0);
+ atomic_init(&y, 0);
+
+ printf("Main thread: creating 4 threads\n");
+ thrd_create(&t1, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
+ thrd_create(&t3, (thrd_start_t)&c, NULL);
+ thrd_create(&t4, (thrd_start_t)&d, NULL);
+
+ thrd_join(t1);
+ thrd_join(t2);
+ thrd_join(t3);
+ thrd_join(t4);
+ printf("Main thread is finished\n");
+
+ return 0;
+}
--- /dev/null
+#include <stdio.h>
+#include <threads.h>
+#include <atomic>
+
+std::atomic_int x;
+std::atomic_int y;
+
+static void a(void *obj)
+{
+ printf("x: %d\n", x.load(std::memory_order_relaxed));
+ y.store(1, std::memory_order_relaxed);
+}
+
+static void b(void *obj)
+{
+ printf("y: %d\n", y.load(std::memory_order_relaxed));
+ x.store(1, std::memory_order_relaxed);
+}
+
+int user_main(int argc, char **argv)
+{
+ thrd_t t1, t2;
+
+ atomic_init(&x, 0);
+ atomic_init(&y, 0);
+
+ printf("Main thread: creating 2 threads\n");
+ thrd_create(&t1, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
+
+ thrd_join(t1);
+ thrd_join(t2);
+ printf("Main thread is finished\n");
+
+ return 0;
+}
--- /dev/null
+#include <stdio.h>
+#include <threads.h>
+#include <atomic>
+
+std::atomic_int x;
+std::atomic_int y;
+
+static void a(void *obj)
+{
+ x.store(1, std::memory_order_relaxed);
+ y.store(1, std::memory_order_relaxed);
+}
+
+static void b(void *obj)
+{
+ printf("y1: %d\n", y.load(std::memory_order_relaxed));
+ printf("x1: %d\n", x.load(std::memory_order_relaxed));
+}
+
+static void c(void *obj)
+{
+ printf("x2: %d\n", x.load(std::memory_order_relaxed));
+ printf("y2: %d\n", y.load(std::memory_order_relaxed));
+}
+
+int user_main(int argc, char **argv)
+{
+ thrd_t t1, t2, t3;
+
+ atomic_init(&x, 0);
+ atomic_init(&y, 0);
+
+ printf("Main thread: creating 3 threads\n");
+ thrd_create(&t1, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
+ thrd_create(&t3, (thrd_start_t)&c, NULL);
+
+ thrd_join(t1);
+ thrd_join(t2);
+ thrd_join(t3);
+ printf("Main thread is finished\n");
+
+ return 0;
+}
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+#include <threads.h>
+#include <atomic>
+
+std::atomic_int x;
+std::atomic_int y;
+std::atomic_int z;
+
+static int N = 1;
+
+static void a(void *obj)
+{
+ for (int i = 0; i < N; i++) {
+ x.store(2 * i + 1, std::memory_order_release);
+ y.store(i + 1, std::memory_order_release);
+ z.store(i + 1, std::memory_order_release);
+ x.store(2 * i + 2, std::memory_order_release);
+ }
+}
+
+static void b(void *obj)
+{
+ printf("x: %d\n", x.load(std::memory_order_acquire));
+ printf("y: %d\n", y.load(std::memory_order_acquire));
+ printf("z: %d\n", z.load(std::memory_order_acquire));
+ printf("x: %d\n", x.load(std::memory_order_acquire));
+}
+
+int user_main(int argc, char **argv)
+{
+ thrd_t t1, t2;
+
+ if (argc > 1)
+ N = atoi(argv[1]);
+
+ printf("N: %d\n", N);
+
+ atomic_init(&x, 0);
+ atomic_init(&y, 0);
+ atomic_init(&z, 0);
+
+ printf("Main thread: creating 2 threads\n");
+ thrd_create(&t1, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
+
+ thrd_join(t1);
+ thrd_join(t2);
+ printf("Main thread is finished\n");
+
+ return 0;
+}
--- /dev/null
+#include <stdio.h>
+#include <threads.h>
+#include <atomic>
+
+std::atomic_int x;
+std::atomic_int y;
+
+static void a(void *obj)
+{
+ x.store(1, std::memory_order_relaxed);
+ printf("y: %d\n", y.load(std::memory_order_relaxed));
+}
+
+static void b(void *obj)
+{
+ y.store(1, std::memory_order_relaxed);
+ printf("x: %d\n", x.load(std::memory_order_relaxed));
+}
+
+int user_main(int argc, char **argv)
+{
+ thrd_t t1, t2;
+
+ atomic_init(&x, 0);
+ atomic_init(&y, 0);
+
+ printf("Main thread: creating 2 threads\n");
+ thrd_create(&t1, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
+
+ thrd_join(t1);
+ thrd_join(t2);
+ printf("Main thread is finished\n");
+
+ return 0;
+}
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+#include <threads.h>
+#include <atomic>
+
+static int N = 2;
+
+std::atomic_int *x;
+
+static void a(void *obj)
+{
+ int idx = *((int *)obj);
+
+ if (idx > 0)
+ x[idx - 1].load(std::memory_order_relaxed);
+
+ if (idx < N)
+ x[idx].store(1, std::memory_order_relaxed);
+ else
+ x[0].load(std::memory_order_relaxed);
+}
+
+int user_main(int argc, char **argv)
+{
+ thrd_t *threads;
+ int *indexes;
+
+ if (argc > 1)
+ N = atoi(argv[1]);
+ if (N < 2) {
+ printf("Error: must have N >= 2\n");
+ return 1;
+ }
+ printf("N: %d\n", N);
+
+ threads = (thrd_t *)malloc((N + 1) * sizeof(thrd_t));
+ x = (std::atomic_int *)malloc(N * sizeof(std::atomic_int));
+ indexes = (int *)malloc((N + 1) * sizeof(int));
+
+ for (int i = 0; i < N + 1; i++)
+ indexes[i] = i;
+
+ for (int i = 0; i < N; i++)
+ atomic_init(&x[i], 0);
+
+ for (int i = 0; i < N + 1; i++)
+ thrd_create(&threads[i], (thrd_start_t)&a, (void *)&indexes[i]);
+
+ for (int i = 0; i < N + 1; i++)
+ thrd_join(threads[i]);
+
+ return 0;
+}