all: $(TESTNAME)
$(TESTNAME): $(HEADERS) $(OBJECTS)
- $(CC) -o $@ $^ $(CPPFLAGS) $(LDFLAGS)
+ $(CC) -o $@ $(OBJECTS) $(CPPFLAGS) $(LDFLAGS)
%.o: %.c
$(CC) -c -o $@ $< $(CPPFLAGS)
static void main_task(void *param)
{
- unsigned i, j;
- unsigned val;
+ unsigned int i, j;
+ unsigned int val;
int pid = *((int *)param);
for (i = 0; i < iterations; i++) {
val = 1 + pid * iterations + i;
+ printf("worker %d, enqueueing: %u\n", pid, val);
enqueue(queue, val);
val = dequeue(queue);
+ printf("worker %d, dequeued: %u\n", pid, val);
}
}
next = atomic_load(&q->nodes[get_ptr(tail)].next);
if (tail == atomic_load(&q->tail)) {
if (get_ptr(next) == 0) { // == NULL
- pointer val = MAKE_POINTER(node, get_count(next) + 1);
+ pointer value = MAKE_POINTER(node, get_count(next) + 1);
success = atomic_compare_exchange_weak(&q->nodes[get_ptr(tail)].next,
- &next,
- val);
+ &next, value);
}
if (!success) {
unsigned int ptr = get_ptr(atomic_load(&q->nodes[get_ptr(tail)].next));
- pointer val = MAKE_POINTER(ptr,
+ pointer value = MAKE_POINTER(ptr,
get_count(tail) + 1);
atomic_compare_exchange_strong(&q->tail,
- &tail,
- val);
+ &tail, value);
thrd_yield();
}
}
if (get_ptr(next) == 0) { // NULL
return 0; // NULL
}
- atomic_compare_exchange_weak(&q->tail,
+ atomic_compare_exchange_strong(&q->tail,
&tail,
MAKE_POINTER(get_ptr(next), get_count(tail) + 1));
thrd_yield();