Skip to content

Commit

Permalink
better concurrency test
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Guzzo committed Jun 10, 2014
1 parent f1a32f8 commit ab01572
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions test/queue_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ int main(int argc, char **argv) {
ut_testing("Threaded queue (%d pull-workers, %d items pushed to the queue from the main thread)",
num_parallel_threads, num_queued_items);

for (i = 0; i < num_parallel_threads; i++) {
pthread_create(&threads[i], NULL, queue_worker, &arg);
}

for (i = 0; i < num_queued_items; i++) {
char *val = malloc(21);
sprintf(val, "%d", i);
queue_push_right(arg.queue, val);
}

for (i = 0; i < num_parallel_threads; i++) {
pthread_create(&threads[i], NULL, queue_worker, &arg);
}

while(queue_count(arg.queue))
usleep(500);

Expand All @@ -138,7 +138,6 @@ int main(int argc, char **argv) {
pthread_join(threads[i], NULL);
}


ut_result(arg.count == num_queued_items, "Handled items should have been %d (was %d)", num_queued_items, arg.count);

queue_destroy(arg.queue);
Expand All @@ -152,16 +151,16 @@ int main(int argc, char **argv) {
ut_testing("Threaded queue reverse (%d pull-workers, %d items pushed to the queue from the main thread)",
num_parallel_threads, num_queued_items);

for (i = 0; i < num_parallel_threads; i++) {
pthread_create(&threads[i], NULL, queue_worker, &arg);
}

for (i = 0; i < num_queued_items; i++) {
char *val = malloc(21);
sprintf(val, "%d", i);
queue_push_left(arg.queue, val);
}

for (i = 0; i < num_parallel_threads; i++) {
pthread_create(&threads[i], NULL, queue_worker, &arg);
}

while(queue_count(arg.queue))
usleep(500);

Expand Down

0 comments on commit ab01572

Please sign in to comment.