1 /* A small multi-threaded test case.
2 
3    Copyright 2004
4    Free Software Foundation, Inc.
5 
6    This file is part of GDB.
7 
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 2 of the License, or
11    (at your option) any later version.
12 
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.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place - Suite 330,
21    Boston, MA 02111-1307, USA.  */
22 
23 #include <pthread.h>
24 #include <stdio.h>
25 #include <time.h>
26 
27 void
cond_wait(pthread_cond_t * cond,pthread_mutex_t * mut)28 cond_wait (pthread_cond_t *cond, pthread_mutex_t *mut)
29 {
30   pthread_mutex_lock(mut);
31   pthread_cond_wait (cond, mut);
32   pthread_mutex_unlock (mut);
33 }
34 
35 void
noreturn(void)36 noreturn (void)
37 {
38   pthread_mutex_t mut;
39   pthread_cond_t cond;
40 
41   pthread_mutex_init (&mut, NULL);
42   pthread_cond_init (&cond, NULL);
43 
44   /* Wait for a condition that will never be signaled, so we effectively
45      block the thread here.  */
46   cond_wait (&cond, &mut);
47 }
48 
49 void *
forever_pthread(void * unused)50 forever_pthread (void *unused)
51 {
52   noreturn ();
53 }
54 
55 void
break_me(void)56 break_me (void)
57 {
58   /* Just an anchor to help putting a breakpoint.  */
59 }
60 
61 int
main(void)62 main (void)
63 {
64   pthread_t forever;
65   const struct timespec ts = { 0, 10000000 }; /* 0.01 sec */
66 
67   pthread_create (&forever, NULL, forever_pthread, NULL);
68   for (;;)
69     {
70       nanosleep (&ts, NULL);
71       break_me();
72     }
73 
74   return 0;
75 }
76 
77