1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2002-2019 Free Software Foundation, Inc.
5 Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003, 2007, 2008, 2009
6 Free Software Foundation, Inc.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 This file is copied from schedlock.c. */
28 void *thread_function (void *arg
); /* Pointer to function executed by each thread */
30 static pthread_barrier_t threads_started_barrier
;
32 static pthread_barrier_t threads_started_barrier2
;
36 static int num_threads
= NUM
;
38 static unsigned int shared_var
= 1;
42 pthread_t threads
[NUM
];
46 pthread_barrier_init (&threads_started_barrier
, NULL
, NUM
+ 1);
48 pthread_barrier_init (&threads_started_barrier2
, NULL
, 2);
50 for (i
= 0; i
< NUM
; i
++)
52 res
= pthread_create (&threads
[i
],
58 pthread_barrier_wait (&threads_started_barrier
);
60 pthread_barrier_wait (&threads_started_barrier2
); /* all threads started */
62 pthread_join (threads
[0], NULL
);
64 sleep (180); /* first child thread exited */
74 void *thread_function (void *arg
) {
75 int my_number
= (long) arg
;
77 pthread_barrier_wait (&threads_started_barrier
);
81 /* Don't run forever. Run just short of it :) */
82 while (shared_var
> 0)
85 usleep (1); /* Loop increment. */
90 pthread_barrier_wait (&threads_started_barrier2
);