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 #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 i, j;
45 
46   pthread_attr_init (&attr);
47   pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
48 
49   /* Create a ton of quick-executing threads, then wait for them to
50      complete.  */
51   for (i = 0; i < 1000; ++i)
52     {
53       for (j = 0; j < 256; ++j)
54 	{
55 	  pthread_create (&threads[j], &attr, thread_function,
56 			  (void *)(i * 1000 + j));
57 	}
58 
59       for (j = 0; j < 256; ++j)
60 	{
61 	  pthread_join (threads[j], NULL);
62 	}
63     }
64 
65   pthread_attr_destroy (&attr);
66 
67   return 0;
68 }
69