5 #include "libinterface.h"
6 #define PROBLEMSIZE 100
18 int old_seq = load_32(&_seq);
20 if (old_seq % 2 == 1) {
23 res = load_32(&_data);
24 int seq = load_32(&_seq);
26 if (seq == old_seq) { // relaxed
34 int seqlock_write(int new_data) {
35 int old_seq = load_32(&_seq);
37 if (old_seq % 2 == 1) {
40 int new_seq = old_seq + 1;
41 int cas_value = rmw_32(CAS, &_seq, old_seq, new_seq);
42 if (cas_value == old_seq) {
43 store_32(&_data, new_data);
44 rmw_32(ADD, &_seq, /*dummy */0, 1);
53 static void a(void *obj) {
54 for (int i = 0; i < PROBLEMSIZE; i++)
58 static void b(void *obj) {
60 for (int i = 0; i < PROBLEMSIZE; i++)
64 static void c(void *obj) {
66 for (int i = 0; i < PROBLEMSIZE; i++)
70 int user_main(int argc, char **argv) {
71 thrd_t t1; thrd_t t2; thrd_t t3;
74 thrd_create(&t1, (thrd_start_t)&a, NULL);
75 thrd_create(&t2, (thrd_start_t)&b, NULL);
76 thrd_create(&t3, (thrd_start_t)&c, NULL);