static struct testthread {
pthread_t pt;
struct seqlock sqlo;
- size_t counter, nullops;
+ _Atomic size_t counter, nullops;
} thr[NTHREADS];
struct testrun {
{ \
size_t i = 0, n = 0;
-#define endtestrun \
- thr[offset].counter = i; \
- thr[offset].nullops = n; \
-}
+#define endtestrun \
+ atomic_store_explicit(&thr[offset].counter, i, memory_order_seq_cst); \
+ atomic_store_explicit(&thr[offset].nullops, n, memory_order_seq_cst); \
+ }
deftestrun(add, "add vs. add", 0, false)
for (; i < NITEM / NTHREADS; i++)
sv = seqlock_bump(&sqlo) - SEQLOCK_INCR;
for (size_t i = 0; i < NTHREADS; i++) {
seqlock_wait(&thr[i].sqlo, seqlock_cur(&sqlo));
- s += thr[i].counter;
- n += thr[i].nullops;
- thr[i].counter = 0;
- thr[i].nullops = 0;
+ s += atomic_load_explicit(&thr[i].counter, memory_order_seq_cst);
+ n += atomic_load_explicit(&thr[i].nullops, memory_order_seq_cst);
+ atomic_store_explicit(&thr[i].counter, 0, memory_order_seq_cst);
+ atomic_store_explicit(&thr[i].nullops, 0, memory_order_seq_cst);
}
delta = monotime_since(&tv, NULL);