1/* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2021-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#include <unistd.h> 19#include <pthread.h> 20#include <assert.h> 21 22#define NUM_THREADS 4 23 24static pthread_barrier_t barrier; 25 26static void * 27thread_function (void *arg) 28{ 29 pthread_barrier_wait (&barrier); 30 31 for (int i = 0; i < 30; i++) 32 sleep (1); 33 34 return NULL; 35} 36 37static void 38all_threads_started (void) 39{} 40 41int 42main (void) 43{ 44 pthread_t threads[NUM_THREADS]; 45 46 pthread_barrier_init (&barrier, NULL, NUM_THREADS + 1); 47 48 for (int i = 0; i < NUM_THREADS; i++) 49 { 50 int res = pthread_create (&threads[i], NULL, thread_function, NULL); 51 assert (res == 0); 52 } 53 54 pthread_barrier_wait (&barrier); 55 all_threads_started (); 56 57 for (int i = 0; i < NUM_THREADS; i++) 58 { 59 int res = pthread_join (threads[i], NULL); 60 assert (res == 0); 61 } 62 63 return 0; 64} 65 66