1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2015-2016 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/>. */
29 pthread_barrier_t
*barrier
;
33 thread_func (void *varg
)
35 struct thread_data
*arg
= (struct thread_data
*) varg
;
38 res
= pthread_setname_np (pthread_self (), arg
->name
);
41 pthread_barrier_wait (arg
->barrier
);
43 pthread_barrier_wait (arg
->barrier
);
49 all_threads_ready (void)
54 main (int argc
, char **argv
)
56 pthread_t threads
[NUM_THREADS
];
57 struct thread_data args
[NUM_THREADS
];
58 pthread_barrier_t barrier
;
60 const char *names
[] = { "carrot", "potato", "celery" };
64 /* Make sure that NAMES contains NUM_THREADS elements. */
65 assert (sizeof (names
) / sizeof (names
[0]) == NUM_THREADS
);
67 res
= pthread_barrier_init (&barrier
, NULL
, NUM_THREADS
+ 1);
70 res
= pthread_setname_np (pthread_self (), "main");
73 for (i
= 0; i
< NUM_THREADS
; i
++)
75 struct thread_data
*arg
= &args
[i
];
78 arg
->barrier
= &barrier
;
80 res
= pthread_create (&threads
[i
], NULL
, thread_func
, arg
);
84 pthread_barrier_wait (&barrier
);
88 pthread_barrier_wait (&barrier
);
90 for (i
= 0; i
< NUM_THREADS
; i
++)
92 res
= pthread_join (threads
[i
], NULL
);