diff options
author | Florian Weimer <fweimer@redhat.com> | 2018-07-25 16:31:45 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2018-07-25 16:31:45 +0200 |
commit | d6b8f8470990db2d36b8e50f1055a673fdf1cea0 (patch) | |
tree | 1ba242d4123707db42c35a352ff4e95671e81d64 /nptl/tst-cnd-broadcast.c | |
parent | x86-64/CET: Extend ucontext_t to save shadow stack (diff) | |
download | glibc-d6b8f8470990db2d36b8e50f1055a673fdf1cea0.tar.gz glibc-d6b8f8470990db2d36b8e50f1055a673fdf1cea0.tar.bz2 glibc-d6b8f8470990db2d36b8e50f1055a673fdf1cea0.zip |
C11 threads: Fix timeout and locking issues
Diffstat (limited to 'nptl/tst-cnd-broadcast.c')
-rw-r--r-- | nptl/tst-cnd-broadcast.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/nptl/tst-cnd-broadcast.c b/nptl/tst-cnd-broadcast.c index 90d6843154..62a4ab5a39 100644 --- a/nptl/tst-cnd-broadcast.c +++ b/nptl/tst-cnd-broadcast.c @@ -17,6 +17,7 @@ <http://www.gnu.org/licenses/>. */ #include <threads.h> +#include <stdbool.h> #include <stdio.h> #include <unistd.h> @@ -28,12 +29,16 @@ static cnd_t cond; /* Mutex to control wait on cond. */ static mtx_t mutex; +/* Number of threads which have entered the cnd_wait region. */ +static unsigned int waiting_threads; + /* Code executed by each thread. */ static int child_wait (void* data) { /* Wait until parent thread sends broadcast here. */ mtx_lock (&mutex); + ++waiting_threads; cnd_wait (&cond, &mutex); mtx_unlock (&mutex); @@ -61,7 +66,16 @@ do_test (void) } /* Wait for other threads to reach their wait func. */ - thrd_sleep (&((struct timespec){.tv_sec = 2}), NULL); + while (true) + { + mtx_lock (&mutex); + TEST_VERIFY (waiting_threads <= N); + bool done_waiting = waiting_threads == N; + mtx_unlock (&mutex); + if (done_waiting) + break; + thrd_sleep (&((struct timespec){.tv_nsec = 100 * 1000 * 1000}), NULL); + } mtx_lock (&mutex); if (cnd_broadcast (&cond) != thrd_success) |