ignore invalid DOF provider sections
[binutils-gdb.git] / gdb / testsuite / gdb.threads / multi-create.c
blob227b9bc1e39c5b5528f62ca58f194b18cdd4e937
1 /* Create threads from multiple threads in parallel.
2 Copyright 2007-2015 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <limits.h>
23 #define NUM_CREATE 1
24 #define NUM_THREAD 8
26 void *
27 thread_function (void *arg)
29 int x = * (int *) arg;
31 printf ("Thread <%d> executing\n", x);
33 return NULL;
36 void *
37 create_function (void *arg)
39 pthread_attr_t attr;
40 pthread_t threads[NUM_THREAD];
41 int args[NUM_THREAD];
42 int i = * (int *) arg;
43 int j;
45 pthread_attr_init (&attr); /* set breakpoint 1 here. */
46 pthread_attr_setstacksize (&attr, 2*PTHREAD_STACK_MIN);
48 /* Create a ton of quick-executing threads, then wait for them to
49 complete. */
50 for (j = 0; j < NUM_THREAD; ++j)
52 args[j] = i * 1000 + j;
53 pthread_create (&threads[j], &attr, thread_function, &args[j]);
56 for (j = 0; j < NUM_THREAD; ++j)
57 pthread_join (threads[j], NULL);
59 pthread_attr_destroy (&attr);
61 return NULL;
64 int
65 main (int argc, char **argv)
67 pthread_attr_t attr;
68 pthread_t threads[NUM_CREATE];
69 int args[NUM_CREATE];
70 int n, i;
72 pthread_attr_init (&attr);
73 pthread_attr_setstacksize (&attr, 2*PTHREAD_STACK_MIN);
75 for (n = 0; n < 100; ++n)
77 for (i = 0; i < NUM_CREATE; i++)
79 args[i] = i;
80 pthread_create (&threads[i], &attr, create_function, &args[i]);
83 create_function (&i);
84 for (i = 0; i < NUM_CREATE; i++)
85 pthread_join (threads[i], NULL);
88 pthread_attr_destroy (&attr);
90 return 0;