diff options
author | Alan Hayward <alan.hayward@arm.com> | 2018-09-26 14:06:54 +0100 |
---|---|---|
committer | Alan Hayward <alan.hayward@arm.com> | 2018-09-27 10:48:20 +0100 |
commit | 9fc3183f0f8ab8ec85f0e5f65bae9e18ddf545a0 (patch) | |
tree | 844bce4744e06f5979038b1fb3a7115de550c0f2 /gdb | |
parent | 115d0c14437a07c686e58d8c0bf30755fb379c68 (diff) | |
download | gdb-9fc3183f0f8ab8ec85f0e5f65bae9e18ddf545a0.zip gdb-9fc3183f0f8ab8ec85f0e5f65bae9e18ddf545a0.tar.gz gdb-9fc3183f0f8ab8ec85f0e5f65bae9e18ddf545a0.tar.bz2 |
testsuite: Fix race condition in check-libthread-db
It is possible for the created thread to reach the breakpoint before
the main thread has set errno to 23.
Prevent this using a pthread barrier.
* gdb.threads/check-libthread-db.c (thread_routine): Use a
pthread barrier.
(main): Likewise.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/check-libthread-db.c | 8 |
2 files changed, 14 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 2b4b097..2072705 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-09-27 Alan Hayward <alan.hayward@arm.com> + + * gdb.threads/check-libthread-db.c (thread_routine): Use a + pthread barrier. + (main): Likewise. + 2018-09-26 Andrew Burgess <andrew.burgess@embecosm.com> * gdb.base/large-frame-1.c: New file. diff --git a/gdb/testsuite/gdb.threads/check-libthread-db.c b/gdb/testsuite/gdb.threads/check-libthread-db.c index 85a97a9..2d9aec4 100644 --- a/gdb/testsuite/gdb.threads/check-libthread-db.c +++ b/gdb/testsuite/gdb.threads/check-libthread-db.c @@ -23,6 +23,10 @@ #include <pthread.h> #include <errno.h> +/* This barrier ensures we only reach the initial breakpoint after both threads + have set errno. */ +pthread_barrier_t start_threads_barrier; + static void break_here (void) { @@ -32,6 +36,7 @@ static void * thread_routine (void *arg) { errno = 42; + pthread_barrier_wait (&start_threads_barrier); break_here (); @@ -47,6 +52,8 @@ main (int argc, char *argv) pthread_t the_thread; int err; + pthread_barrier_init (&start_threads_barrier, NULL, 2); + err = pthread_create (&the_thread, NULL, thread_routine, NULL); if (err != 0) { @@ -55,6 +62,7 @@ main (int argc, char *argv) } errno = 23; + pthread_barrier_wait (&start_threads_barrier); err = pthread_join (the_thread, NULL); if (err != 0) |