return -1;
}
+bool succ1, succ2;
+
static void main_task(void *param)
{
unsigned int val;
int pid = *((int *)param);
-
if (!pid) {
input[0] = 17;
enqueue(queue, input[0]);
- output[0] = dequeue(queue);
+ succ1 = dequeue(queue, &output[0]);
+ //printf("Dequeue: %d\n", output[0]);
} else {
input[1] = 37;
enqueue(queue, input[1]);
- output[1] = dequeue(queue);
+ succ2 = dequeue(queue, &output[1]);
}
}
printf("input[%d] = %u\n", i, input[i]);
for (i = 0; i < num_threads; i++)
printf("output[%d] = %u\n", i, output[i]);
- MODEL_ASSERT(in_sum == out_sum);
+ if (succ1 && succ2)
+ MODEL_ASSERT(in_sum == out_sum);
+ else
+ MODEL_ASSERT (false);
free(param);
free(threads);
release, release);
}
-unsigned int dequeue(queue_t *q)
+bool dequeue(queue_t *q, unsigned int *retVal)
{
- unsigned int value;
int success = 0;
pointer head;
pointer tail;
MODEL_ASSERT(get_ptr(next) != POISON_IDX);
if (get_ptr(next) == 0) { // NULL
- return 0; // NULL
+ return false; // NULL
}
atomic_compare_exchange_strong_explicit(&q->tail,
&tail,
release, release);
thrd_yield();
} else {
- value = load_32(&q->nodes[get_ptr(next)].value);
+ *retVal = load_32(&q->nodes[get_ptr(next)].value);
success = atomic_compare_exchange_strong_explicit(&q->head,
&head,
MAKE_POINTER(get_ptr(next), get_count(head) + 1),
}
}
reclaim(get_ptr(head));
- return value;
+ return true;
}
void init_queue(queue_t *q, int num_threads);
void enqueue(queue_t *q, unsigned int val);
-unsigned int dequeue(queue_t *q);
+bool dequeue(queue_t *q, unsigned int *retVal);
int get_thread_num();