1/* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2016-2023 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*/ 19 20#include <pthread.h> 21#include <unistd.h> 22 23#define NUM_THREADS 2 24 25static pthread_barrier_t barrier; 26 27static void 28child_sub_function (void) 29{ 30 volatile int dummy = 0; 31 while (1) 32 /* Dummy loop body to allow setting breakpoint. */ 33 dummy = !dummy; /* thread loop line */ 34} 35 36static void * 37child_function (void *args) 38{ 39 pthread_barrier_wait (&barrier); 40 41 child_sub_function (); /* thread caller line */ 42 43 return NULL; 44} 45 46int 47main (void) 48{ 49 int i = 0; 50 pthread_t threads[NUM_THREADS]; 51 52 /* Make the test exit eventually. */ 53 alarm (20); 54 55 /* Initialize the barrier, NUM_THREADS plus the main thread. */ 56 pthread_barrier_init (&barrier, NULL, NUM_THREADS + 1); 57 58 for (i = 0; i < NUM_THREADS; i++) 59 pthread_create (&threads[i], NULL, child_function, NULL); 60 61 pthread_barrier_wait (&barrier); 62 63 volatile int dummy = 0; 64 while (1) 65 /* Dummy loop body to allow setting breakpoint. */ 66 dummy = !dummy; /* main break line */ 67 68 return 0; 69} 70