DIRS := barrier mcs-lock mpmc-queue spsc-queue spsc-bugfix linuxrwlocks \
dekker-fences chase-lev-deque ms-queue chase-lev-deque-bugfix \
- concurrent-hashmap
+ concurrent-hashmap seqlock
.PHONY: $(DIRS)
}
void write(int new_data) {
+ int old_seq = _seq.load(wildcard(4)); // acquire
while (true) {
- // This might be a relaxed too
- int old_seq = _seq.load(wildcard(4)); // acquire
if (old_seq % 2 == 1)
continue; // Retry
lock = new seqlock_t();
thrd_create(&t1, (thrd_start_t)&a, NULL);
- thrd_create(&t2, (thrd_start_t)&b, 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(t2);
thrd_join(t3);
return 0;
}
int old_seq = _seq.load(memory_order_acquire); // acquire
if (old_seq % 2 == 1) continue;
- int res = _data.load(memory_order_acquire); // acquire
+ int res = _data.load(memory_order_acquire);
if (_seq.load(memory_order_relaxed) == old_seq) { // relaxed
return res;
}
}
void write(int new_data) {
+ int old_seq = _seq.load(memory_order_acquire); // acquire
while (true) {
// This might be a relaxed too
- int old_seq = _seq.load(memory_order_acquire); // acquire
if (old_seq % 2 == 1)
continue; // Retry
- // Should be relaxed!!!
if (_seq.compare_exchange_strong(old_seq, old_seq + 1,
- memory_order_relaxed, memory_order_relaxed)) // relaxed
+ memory_order_acq_rel, memory_order_acquire))
break;
}
// Update the data
- _data.store(new_data, memory_order_release); // release
+ _data.store(new_data, memory_order_release); // Can be relaxed
_seq.fetch_add(1, memory_order_release); // release
}
}
static void c(void *obj) {
+ lock->write(2);
int r1 = lock->read();
}
lock = new seqlock_t();
thrd_create(&t1, (thrd_start_t)&a, NULL);
- thrd_create(&t2, (thrd_start_t)&b, 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(t2);
thrd_join(t3);
return 0;
}