1/* This testcase is part of GDB, the GNU debugger.
2
3   Copyright 2014-2020 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#ifdef USE_THREADS
19
20#include <unistd.h>
21#include <pthread.h>
22
23#define NUM 5
24
25pthread_barrier_t barrier;
26
27void *
28thread_function (void *arg)
29{
30  volatile unsigned int counter = 1;
31
32  pthread_barrier_wait (&barrier);
33
34  while (counter > 0)
35    {
36      counter++;
37      usleep (1);
38    }
39
40  pthread_exit (NULL);
41}
42
43#endif /* USE_THREADS */
44
45void
46setup (void)
47{
48#ifdef USE_THREADS
49  pthread_t threads[NUM];
50  int i;
51
52  pthread_barrier_init (&barrier, NULL, NUM + 1);
53  for (i = 0; i < NUM; i++)
54    pthread_create (&threads[i], NULL, thread_function, NULL);
55  pthread_barrier_wait (&barrier);
56#endif /* USE_THREADS */
57}
58
59int
60main (void)
61{
62  setup ();
63  return 0; /* set break here */
64}
65