1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2008-2014 Free Software Foundation, Inc.
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.
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.
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/>. */
25 #include <sys/types.h>
30 volatile int done = 0;
31 static pthread_barrier_t barrier;
43 thread_function (void *arg)
45 int x = * (int *) arg;
47 printf ("Thread <%d> executing\n", x);
49 pthread_barrier_wait (&barrier);
58 thread_forker (void *arg)
60 int x = * (int *) arg;
66 printf ("Thread forker <%d> executing\n", x);
68 pthread_barrier_wait (&barrier);
70 switch ((pid = fork ()))
79 i = pthread_create (&thread, NULL, start, NULL);
81 i = pthread_join (thread, NULL);
93 pthread_t threads[NUMTHREADS];
99 i = pthread_barrier_init (&barrier, NULL, NUMTHREADS);
102 /* Create a few threads that do mostly nothing, and then one that
104 for (j = 0; j < NUMTHREADS - 1; ++j)
107 pthread_create (&threads[j], NULL, thread_function, &args[j]);
111 pthread_create (&threads[j], NULL, thread_forker, &args[j]);
113 for (j = 0; j < NUMTHREADS; ++j)
115 pthread_join (threads[j], NULL);