1 /* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2009-2015 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18 #include <pthread.h> 19 #include <unistd.h> 20 #include <stdlib.h> 21 #include <signal.h> 22 23 unsigned int args[2]; 24 25 pthread_barrier_t barrier; 26 pthread_t child_thread_2, child_thread_3; 27 28 void 29 callme (void) 30 { 31 } 32 33 void * 34 child_function_3 (void *arg) 35 { 36 int my_number = (long) arg; 37 volatile int *myp = (int *) &args[my_number]; 38 39 pthread_barrier_wait (&barrier); 40 41 while (*myp > 0) 42 { 43 (*myp) ++; 44 callme (); /* set breakpoint thread 3 here */ 45 } 46 47 pthread_exit (NULL); 48 } 49 50 void * 51 child_function_2 (void *arg) 52 { 53 int my_number = (long) arg; 54 volatile int *myp = (int *) &args[my_number]; 55 56 pthread_barrier_wait (&barrier); 57 58 while (*myp > 0) 59 { 60 (*myp) ++; 61 callme (); /* set breakpoint thread 2 here */ 62 } 63 64 pthread_exit (NULL); 65 } 66 67 static int 68 wait_threads (void) 69 { 70 return 1; /* in wait_threads */ 71 } 72 73 int 74 main () 75 { 76 int res; 77 long i; 78 79 /* Call these early so that PLTs for these are resolved soon, 80 instead of in the threads. RTLD_NOW should work as well. */ 81 usleep (0); 82 pthread_barrier_init (&barrier, NULL, 1); 83 pthread_barrier_wait (&barrier); 84 85 pthread_barrier_init (&barrier, NULL, 2); 86 87 i = 0; 88 args[i] = 1; 89 res = pthread_create (&child_thread_2, 90 NULL, child_function_2, (void *) i); 91 pthread_barrier_wait (&barrier); 92 callme (); 93 94 i = 1; 95 args[i] = 1; 96 res = pthread_create (&child_thread_3, 97 NULL, child_function_3, (void *) i); 98 pthread_barrier_wait (&barrier); 99 wait_threads (); /* set wait-threads breakpoint here */ 100 101 pthread_join (child_thread_2, NULL); 102 pthread_join (child_thread_3, NULL); 103 104 exit(EXIT_SUCCESS); 105 } 106