* configure.in: Add config header.
[binutils-gdb.git] / gdb / testsuite / gdb.mi / pthreads.c
1 #include <stdio.h>
2
3 #include "config.h"
4
5 #ifndef HAVE_PTHREAD_H
6
7 /* Don't even try to compile. In fact, cause a syntax error that we can
8 look for as a compiler error message and know that we have no pthread
9 support. In that case we can just suppress the test completely. */
10
11 #error "no posix threads support"
12
13 #else
14
15 /* OK. We have the right header. If we try to compile this and fail, then
16 there is something wrong and the user should know about it so the testsuite
17 should issue an ERROR result.. */
18
19 #ifdef __linux__
20 #define _MIT_POSIX_THREADS 1 /* GNU/Linux (or at least RedHat 4.0)
21 needs this */
22 #endif
23
24 #include <pthread.h>
25
26 /* Under OSF 2.0 & 3.0 and HPUX 10, the second arg of pthread_create
27 is prototyped to be just a "pthread_attr_t", while under Solaris it
28 is a "pthread_attr_t *". Arg! */
29
30 #if defined (__osf__) || defined (__hpux__)
31 #define PTHREAD_CREATE_ARG2(arg) arg
32 #define PTHREAD_CREATE_NULL_ARG2 null_attr
33 static pthread_attr_t null_attr;
34 #else
35 #define PTHREAD_CREATE_ARG2(arg) &arg
36 #define PTHREAD_CREATE_NULL_ARG2 NULL
37 #endif
38
39 void *
40 routine (void *arg)
41 {
42 sleep (9);
43 printf ("hello thread\n");
44 }
45
46 /* Marker function for the testsuite */
47 void
48 done_making_threads (void)
49 {
50 /* Nothing */
51 };
52
53 void
54 create_thread (void)
55 {
56 pthread_t tid;
57
58 if (pthread_create (&tid, PTHREAD_CREATE_NULL_ARG2, routine, (void *) 0xfeedface))
59 {
60 perror ("pthread_create 1");
61 exit (1);
62 }
63 }
64
65 int
66 main (int argc, char *argv[])
67 {
68 int i;
69
70 /* Create a few threads */
71 for (i = 0; i < 5; i++)
72 create_thread ();
73 done_making_threads ();
74
75 printf ("hello\n");
76 printf ("hello\n");
77 return 0;
78 }
79
80 #endif /* ifndef HAVE_PTHREAD_H */