* gdb.threads/manythreads.c (thread_function, main): Don't cast
[external/binutils.git] / gdb / testsuite / gdb.threads / manythreads.c
1 /* Manythreads test program.
2    Copyright 2004, 2006
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 #include <limits.h>
28
29 void *
30 thread_function (void *arg)
31 {
32   int x = * (int *) arg;
33
34   printf ("Thread <%d> executing\n", x);
35
36   return NULL;
37 }
38
39 int 
40 main (int argc, char **argv)
41 {
42   pthread_attr_t attr;
43   pthread_t threads[256];
44   int args[256];
45   int i, j;
46
47   pthread_attr_init (&attr);
48   pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
49
50   /* Create a ton of quick-executing threads, then wait for them to
51      complete.  */
52   for (i = 0; i < 1000; ++i) 
53     {
54       for (j = 0; j < 256; ++j)
55         {
56           args[j] = i * 1000 + j;
57           pthread_create (&threads[j], &attr, thread_function, &args[j]);
58         }
59
60       for (j = 0; j < 256; ++j)
61         {
62           pthread_join (threads[j], NULL);
63         }
64     }
65
66   pthread_attr_destroy (&attr);
67
68   return 0;
69 }