1 #include <pthread.h> 2 #include <unistd.h> 3 4 static const int NTHREADS = 10; 5 static pthread_barrier_t barrier; 6 7 static void * thread_func(void * p)8thread_func (void *p) 9 { 10 pthread_barrier_wait (&barrier); 11 return NULL; 12 } 13 14 int main(void)15main (void) 16 { 17 alarm (60); 18 19 pthread_t threads[NTHREADS]; 20 pthread_barrier_init (&barrier, NULL, NTHREADS + 2); 21 22 for (int i = 0; i < NTHREADS; i++) 23 pthread_create (&threads[i], NULL, thread_func, NULL); 24 25 pthread_barrier_wait (&barrier); 26 27 for (int i = 0; i < NTHREADS; i++) 28 pthread_join (threads[i], NULL); 29 } 30