int x;
if (t <= b) {
/* Non-empty queue. */
- x = atomic_load_explicit(&a->buffer[b % atomic_load_explicit(&a->size,memory_order_relaxed)], memory_order_relaxed);
+ int size = atomic_load_explicit(&a->size, memory_order_relaxed);
+ if (size == 0)
+ model_print("take: size == 0\n");
+ // TODO: size can be zero here!!
+ x = atomic_load_explicit(&a->buffer[b % size], memory_order_relaxed);
/**
@Begin
@Commit_point_define_check: t != b
atomic_store_explicit(&new_a->size, new_size, memory_order_relaxed);
size_t i;
for(i=top; i < bottom; i++) {
+ if (new_size == 0)
+ model_print("resize: new_size == 0\n");
+ if (size == 0)
+ model_print("resize: size == 0\n");
atomic_store_explicit(&new_a->buffer[i % new_size], atomic_load_explicit(&a->buffer[i % size], memory_order_relaxed), memory_order_relaxed);
}
atomic_store_explicit(&q->array, new_a, memory_order_release);
//Bug in paper...should have next line...
a = (Array *) atomic_load_explicit(&q->array, memory_order_relaxed);
}
- atomic_store_explicit(&a->buffer[b % atomic_load_explicit(&a->size, memory_order_relaxed)], x, memory_order_relaxed);
+ int size = atomic_load_explicit(&a->size, memory_order_relaxed);
+ if (size == 0)
+ model_print("push: size == 0\n");
+ atomic_store_explicit(&a->buffer[b % size], x, memory_order_relaxed);
atomic_thread_fence(memory_order_release);
/**
@Begin
if (t < b) {
/* Non-empty queue. */
Array *a = (Array *) atomic_load_explicit(&q->array, memory_order_acquire);
- x = atomic_load_explicit(&a->buffer[t % atomic_load_explicit(&a->size, memory_order_relaxed)], memory_order_relaxed);
+ int size = atomic_load_explicit(&a->size, memory_order_relaxed);
+ if (size == 0)
+ model_print("steal: size == 0\n");
+ x = atomic_load_explicit(&a->buffer[t % size], memory_order_relaxed);
bool succ = atomic_compare_exchange_strong_explicit(&q->top, &t, t + 1,
memory_order_seq_cst, memory_order_relaxed);
/**
int b;
int c;
-static void task(void * param) {
+static void task1(void * param) {
a=steal(q);
}
+static void task2(void * param) {
+ a=take(q);
+}
+
int user_main(int argc, char **argv)
{
/**
@Entry_point
@End
*/
- thrd_t t;
+ thrd_t t1, t2;
q=create();
- thrd_create(&t, task, 0);
push(q, 1);
push(q, 2);
+ thrd_create(&t1, task1, 0);
+ thrd_create(&t2, task2, 0);
push(q, 4);
b=take(q);
c=take(q);
- thrd_join(t);
+ thrd_join(t1);
+ thrd_join(t2);
bool correct=true;
if (a!=1 && a!=2 && a!=4 && a!= EMPTY)
correct=false;
if (!correct)
printf("a=%d b=%d c=%d\n",a,b,c);
- MODEL_ASSERT(correct);
+ //MODEL_ASSERT(correct);
return 0;
}
//model_print("Write: %d\n", new_data);
}
+/*
+Data *prev = data.load(memory_order_acquire);
+bool succ = false;
+Data *tmp = malloc(sizeof(Data));
+do {
+ tmp->data1=prev->data1+new_data->data1;
+ tmp->data2=prev->data2+new_data->data2;
+ tmp->data3=prev->data3+new_data->data3;
+ succ = data.compare_exchange_strong(prev, tmp,
+ memory_order_release, memory_order_acquire);
+ } while (!succ);
+ //model_print("Write: %d\n", new_data);
+}
+*/
+
void threadA(void *arg) {
Data *dataA = (Data*) malloc(sizeof(Data));
dataA->data1 = 3;