2004-04-22 Jeff Johnston <jjohnstn@redhat.com>
[external/binutils.git] / gdb / testsuite / gdb.threads / manythreads.c
1 #include <pthread.h>
2 #include <stdio.h>
3
4 void *
5 thread_function (void *arg)
6 {
7   int x = (int)arg;
8
9   printf ("Thread <%d> executing\n", x);
10
11   return NULL;
12 }
13
14 int 
15 main (int argc, char **argv)
16 {
17   pthread_attr_t attr;
18   pthread_t threads[256];
19   int i, j;
20
21   pthread_attr_init (&attr);
22
23   /* Create a ton of quick-executing threads, then wait for them to
24      complete.  */
25   for (i = 0; i < 1000; ++i) 
26     {
27       for (j = 0; j < 256; ++j)
28         {
29           pthread_create (&threads[j], &attr, thread_function, 
30                           (void *)(i * 1000 + j));
31         }
32
33       for (j = 0; j < 256; ++j)
34         {
35           pthread_join (threads[j], NULL);
36         }
37     }
38
39   pthread_attr_destroy (&attr);
40
41   return 0;
42 }