2004-04-23 Jeff Johnston <jjohnstn@redhat.com>
[external/binutils.git] / gdb / testsuite / gdb.threads / manythreads.c
1 /* Manythreads test program.
2    Copyright 2004
3    Free Software Foundation, Inc.
4
5    Written by Jeff Johnston <jjohnstn@redhat.com> 
6    Contributed by Red Hat
7
8    This file is part of GDB.
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330,
23    Boston, MA 02111-1307, USA.  */
24
25 #include <pthread.h>
26 #include <stdio.h>
27
28 void *
29 thread_function (void *arg)
30 {
31   int x = (int)arg;
32
33   printf ("Thread <%d> executing\n", x);
34
35   return NULL;
36 }
37
38 int 
39 main (int argc, char **argv)
40 {
41   pthread_attr_t attr;
42   pthread_t threads[256];
43   int i, j;
44
45   pthread_attr_init (&attr);
46
47   /* Create a ton of quick-executing threads, then wait for them to
48      complete.  */
49   for (i = 0; i < 1000; ++i) 
50     {
51       for (j = 0; j < 256; ++j)
52         {
53           pthread_create (&threads[j], &attr, thread_function, 
54                           (void *)(i * 1000 + j));
55         }
56
57       for (j = 0; j < 256; ++j)
58         {
59           pthread_join (threads[j], NULL);
60         }
61     }
62
63   pthread_attr_destroy (&attr);
64
65   return 0;
66 }