]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/pthread_cond_wait.c
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / pthread_cond_wait.c
CommitLineData
8b923272
JB
1/* A small multi-threaded test case.
2
618f726f 3 Copyright 2004-2016 Free Software Foundation, Inc.
8b923272
JB
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
8b923272
JB
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8b923272
JB
19
20#include <pthread.h>
21#include <stdio.h>
22#include <time.h>
37bc665e 23#include <unistd.h>
8b923272
JB
24
25void
26cond_wait (pthread_cond_t *cond, pthread_mutex_t *mut)
27{
28 pthread_mutex_lock(mut);
29 pthread_cond_wait (cond, mut);
30 pthread_mutex_unlock (mut);
31}
32
33void
34noreturn (void)
35{
36 pthread_mutex_t mut;
37 pthread_cond_t cond;
38
39 pthread_mutex_init (&mut, NULL);
40 pthread_cond_init (&cond, NULL);
41
42 /* Wait for a condition that will never be signaled, so we effectively
43 block the thread here. */
44 cond_wait (&cond, &mut);
45}
46
47void *
48forever_pthread (void *unused)
49{
50 noreturn ();
51}
52
53void
54break_me (void)
55{
56 /* Just an anchor to help putting a breakpoint. */
57}
58
59int
60main (void)
61{
62 pthread_t forever;
8b923272
JB
63
64 pthread_create (&forever, NULL, forever_pthread, NULL);
65 for (;;)
66 {
420f4384 67 sleep (2);
8b923272
JB
68 break_me();
69 }
70
71 return 0;
72}
73