diff options
author | Carl Love <cel@us.ibm.com> | 2021-05-21 11:29:26 -0500 |
---|---|---|
committer | Carl Love <cel@us.ibm.com> | 2021-06-02 10:29:36 -0500 |
commit | 170960e8e1413c354a76e3fe83c789407c3dc101 (patch) | |
tree | 4b7d288dd4454dc44a1e783f2a7f26f906d4c88e /gdb/testsuite | |
parent | 8f467114435286e4f78b16fc1f5864acf6488fc0 (diff) | |
download | gdb-170960e8e1413c354a76e3fe83c789407c3dc101.zip gdb-170960e8e1413c354a76e3fe83c789407c3dc101.tar.gz gdb-170960e8e1413c354a76e3fe83c789407c3dc101.tar.bz2 |
Fix threadapply test
The current test case leaves detached processes running at the end of
the test. This patch changes the test to use a barrier wait to ensure all
processes exit cleanly at the end of the tests.
gdb/testsuite/ChangeLog:
2021-06-02 Carl Love <cel@us.ibm.com>
* gdb.threads/threadapply.c: Add global mybarrier.
(main): Add pthread_barrier_init.
(thread_function): Replace while loop with myp increment and
pthread_barrier_wait.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/testsuite/gdb.threads/threadapply.c | 12 |
2 files changed, 12 insertions, 7 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index f34812d..a0469c8 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2021-06-02 Carl Love <cel@us.ibm.com> + + * gdb.threads/threadapply.c: Add global mybarrier. + (main): Add pthread_barrier_init. + (thread_function): Replace while loop with myp increment and + pthread_barrier_wait. + 2021-06-02 Andrew Burgess <andrew.burgess@embecosm.com> * lib/gdb.exp (gdb_compile): Only add the -J option when using a diff --git a/gdb/testsuite/gdb.threads/threadapply.c b/gdb/testsuite/gdb.threads/threadapply.c index 93a3fc8..1ac99b0 100644 --- a/gdb/testsuite/gdb.threads/threadapply.c +++ b/gdb/testsuite/gdb.threads/threadapply.c @@ -27,6 +27,7 @@ void *thread_function(void *arg); /* Pointer to function executed by each thread #define NUM 5 unsigned int args[NUM+1]; +pthread_barrier_t mybarrier; int main() { int res; @@ -35,6 +36,8 @@ int main() { void *thread_result; long i; + pthread_barrier_init(&mybarrier, NULL, NUM + 1); + for (i = 0; i < NUM; i++) { args[i] = 1; /* Init value. */ @@ -69,12 +72,7 @@ void *thread_function(void *arg) { int my_number = (long) arg; int *myp = (int *) &args[my_number]; - /* Don't run forever. Run just short of it :) */ - while (*myp > 0) - { - (*myp) ++; /* Loop increment. */ - } - - pthread_exit(NULL); + (*myp) ++; /* Increment so parent knows child started. */ + pthread_barrier_wait(&mybarrier); } |