1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2008-2024 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/>. */
24 #include <sys/types.h>
29 volatile int done
= 0;
30 static pthread_barrier_t barrier
;
42 thread_function (void *arg
)
44 int x
= * (int *) arg
;
46 printf ("Thread <%d> executing\n", x
);
48 pthread_barrier_wait (&barrier
);
57 thread_forker (void *arg
)
59 int x
= * (int *) arg
;
65 printf ("Thread forker <%d> executing\n", x
);
67 pthread_barrier_wait (&barrier
);
69 switch ((pid
= fork ()))
78 i
= pthread_create (&thread
, NULL
, start
, NULL
);
80 i
= pthread_join (thread
, NULL
);
92 pthread_t threads
[NUMTHREADS
];
98 i
= pthread_barrier_init (&barrier
, NULL
, NUMTHREADS
);
101 /* Create a few threads that do mostly nothing, and then one that
103 for (j
= 0; j
< NUMTHREADS
- 1; ++j
)
106 pthread_create (&threads
[j
], NULL
, thread_function
, &args
[j
]);
110 pthread_create (&threads
[j
], NULL
, thread_forker
, &args
[j
]);
112 for (j
= 0; j
< NUMTHREADS
; ++j
)
114 pthread_join (threads
[j
], NULL
);