all: $(TESTS)
+$(WILDCARD_TESTS): CXXFLAGS += -DWILDCARD
$(WILDCARD_TESTS): %_wildcard : %.cc $(BENCH)_wildcard.h
$(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS)
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;
void push(unsigned int val) {
node *n = new node(val);
- node *old = top.load(acquire);
+ node *old = top.load(relaxed);
do {
- n->next = old;
- } while (!top.compare_exchange_strong(old, n, acq_rel, relaxed));
+ // n->next = old;
+ n->next.store(old, relaxed);
+ } while (!top.compare_exchange_strong(old, n, release, relaxed));
}
unsigned int pop() {
do {
if (!old)
return 0;
- n = old->next;
- } while (!top.compare_exchange_strong(old, n, acq_rel, acquire));
+ //n = old->next;
+ n = old->next.load(relaxed);
+ } while (!top.compare_exchange_strong(old, n, relaxed, relaxed));
return old->value;
}
};
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;
}
};
#include <threads.h>
#include "model-assert.h"
+#ifdef WILDCARD
+#include "stack_wildcard.h"
+#else
#include "stack.h"
+#endif
static int procs = 4;
static stack *s;