[PATCH] kill all threadapply processes at end of test

Carl Love cel@us.ibm.com
Mon May 24 15:30:39 GMT 2021


Simon, Tom, Pedro, GCC maintainers:

I have implemented the test changes to use pthread barrier rather then
the spin loop.  The changes only require changing the test with no
changes to the expect scripts.  

The threadsapply test runs fine with no errors and no processes running
after the test with just the changes to threadapply.c.  This approach
seems to work well and would be better then the previous patches to
kill the processes in the expect script.  

The patch has been tested on Power.  Please let me know if you have any
additional comments or concern. Thanks.

                         Carl Love
----------------------------------------------------------------------
Change test to use barrier wait

gdb/testsuite/ChangeLog:

2021-05-22  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.
---
 gdb/testsuite/gdb.threads/threadapply.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/gdb.threads/threadapply.c b/gdb/testsuite/gdb.threads/threadapply.c
index 93a3fc8e82d..1ac99b07fc1 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);
 }
 
-- 
2.27.0




More information about the Gdb-patches mailing list