From 63396c7d138766cc7b1a01559e4c530291855050 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 6 Jun 2023 15:12:29 -0400 Subject: [PATCH] pthread_barrier_test: Reduce sleep times and increase cycles. This test now reliably reproduces the deadlock reported in #15736. --- .../system/libroot/posix/pthread_barrier_test.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/tests/system/libroot/posix/pthread_barrier_test.cpp b/src/tests/system/libroot/posix/pthread_barrier_test.cpp index d9afc156a1..b89d1549cb 100644 --- a/src/tests/system/libroot/posix/pthread_barrier_test.cpp +++ b/src/tests/system/libroot/posix/pthread_barrier_test.cpp @@ -2,9 +2,10 @@ #include #include #include +#include #define THREAD_COUNT 10 -#define CYCLES 2 +#define CYCLES 20 pthread_barrier_t mybarrier; @@ -14,14 +15,14 @@ void* threadFn(void* id_ptr) for (int i = 0; i < CYCLES; ++i) { int wait_sec = 1 + rand() % 10; - printf("thread %d: Wait %d seconds.\n", thread_id, wait_sec); - sleep(wait_sec); - printf("thread %d: Waiting on barrier...\n", thread_id); + fprintf(stderr, "thread %d: Wait %d microseconds.\n", thread_id, wait_sec * 100); + snooze(wait_sec * 100); + fprintf(stderr, "thread %d: Waiting on barrier...\n", thread_id); int status = pthread_barrier_wait(&mybarrier); if (status == PTHREAD_BARRIER_SERIAL_THREAD) - printf("thread %d: serial thread.\n", thread_id); - printf("thread %d: Finished!\n", thread_id); + fprintf(stderr, "thread %d: serial thread.\n", thread_id); + fprintf(stderr, "thread %d: Finished!\n", thread_id); } return NULL;