struct node {
unsigned int value;
- node *next;
+ // This field does not have to be atomic, but in the inference analysis, we
+ // might have a data race for this field without the proper synchronization.
+ //node *next;
+ atomic<node*> next;
node(unsigned int v) {
value = v;
node *n = new node(val);
node *old = top.load(wildcard(1)); // acquire
do {
- n->next = old;
- } while (!top.compare_exchange_strong(old, n, wildcard(2), wildcard(3)));
- // acq_rel & relaxed
+ // n->next = old;
+ n->next.store(old, wildcard(2));
+ } while (!top.compare_exchange_strong(old, n, wildcard(3), wildcard(4)));
+ // relaxed & relaxed
}
unsigned int pop() {
- node *old = top.load(wildcard(4)); // acquire
+ node *old = top.load(wildcard(5)); // acquire
node *n;
do {
if (!old)
return 0;
- n = old->next;
- } while (!top.compare_exchange_strong(old, n, wildcard(5), wildcard(6)));
- // acq_rel & acquire
+ // n = old->next;
+ n = old->next.load(relaxed);
+ } while (!top.compare_exchange_strong(old, n, wildcard(6), wildcard(7)));
+ // relaxed & relaxed
return old->value;
}
};