4 #include "libinterface.h"
5 #define PROBLEMSIZE 100
17 int old_seq = load_32(&_seq);
19 if (old_seq % 2 == 1) {
22 res = load_32(&_data);
23 int seq = load_32(&_seq);
25 if (seq == old_seq) { // relaxed
33 int seqlock_write(int new_data) {
34 int old_seq = load_32(&_seq);
36 if (old_seq % 2 == 1) {
39 int new_seq = old_seq + 1;
40 int cas_value = rmw_32(CAS, &_seq, old_seq, new_seq);
41 if (cas_value == old_seq) {
42 store_32(&_data, new_data);
43 rmw_32(ADD, &_seq, /*dummy */0, 1);
52 static void a(void *obj) {
53 for (int i = 0; i < PROBLEMSIZE; i++)
57 static void b(void *obj) {
59 for (int i = 0; i < PROBLEMSIZE; i++)
63 static void c(void *obj) {
65 for (int i = 0; i < PROBLEMSIZE; i++)
69 int user_main(int argc, char **argv) {
70 thrd_t t1; thrd_t t2; thrd_t t3;
73 thrd_create(&t1, (thrd_start_t)&a, NULL);
74 thrd_create(&t2, (thrd_start_t)&b, NULL);
75 thrd_create(&t3, (thrd_start_t)&c, NULL);