No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / testsuite / gdb.threads / manythreads.c
blobe39412cde8f97b25a2fefeefce19b74cb989c8c3
1 /* Manythreads test program.
2 Copyright 2004
3 Free Software Foundation, Inc.
5 Written by Jeff Johnston <jjohnstn@redhat.com>
6 Contributed by Red Hat
8 This file is part of GDB.
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.
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.
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. */
25 #include <pthread.h>
26 #include <stdio.h>
27 #include <limits.h>
29 void *
30 thread_function (void *arg)
32 int x = (int)arg;
34 printf ("Thread <%d> executing\n", x);
36 return NULL;
39 int
40 main (int argc, char **argv)
42 pthread_attr_t attr;
43 pthread_t threads[256];
44 int i, j;
46 pthread_attr_init (&attr);
47 pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
49 /* Create a ton of quick-executing threads, then wait for them to
50 complete. */
51 for (i = 0; i < 1000; ++i)
53 for (j = 0; j < 256; ++j)
55 pthread_create (&threads[j], &attr, thread_function,
56 (void *)(i * 1000 + j));
59 for (j = 0; j < 256; ++j)
61 pthread_join (threads[j], NULL);
65 pthread_attr_destroy (&attr);
67 return 0;