OSDN Git Service

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