2004-04-23 18:50:35 +00:00
|
|
|
/* Manythreads test program.
|
2009-01-03 05:58:08 +00:00
|
|
|
Copyright 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
|
2004-04-23 18:50:35 +00:00
|
|
|
|
|
|
|
Written by Jeff Johnston <jjohnstn@redhat.com>
|
|
|
|
Contributed by Red Hat
|
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-08-23 18:08:50 +00:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2004-04-23 18:50:35 +00:00
|
|
|
(at your option) any later version.
|
2007-08-23 18:08:50 +00:00
|
|
|
|
2004-04-23 18:50:35 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-08-23 18:08:50 +00:00
|
|
|
|
2004-04-23 18:50:35 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
2007-08-23 18:08:50 +00:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2004-04-23 18:50:35 +00:00
|
|
|
|
2004-04-22 22:19:40 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdio.h>
|
2004-04-23 19:01:17 +00:00
|
|
|
#include <limits.h>
|
2004-04-22 22:19:40 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
thread_function (void *arg)
|
|
|
|
{
|
2006-10-17 15:52:53 +00:00
|
|
|
int x = * (int *) arg;
|
2004-04-22 22:19:40 +00:00
|
|
|
|
|
|
|
printf ("Thread <%d> executing\n", x);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_t threads[256];
|
2006-10-17 15:52:53 +00:00
|
|
|
int args[256];
|
2004-04-22 22:19:40 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
pthread_attr_init (&attr);
|
2004-04-23 19:01:17 +00:00
|
|
|
pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
|
2004-04-22 22:19:40 +00:00
|
|
|
|
|
|
|
/* Create a ton of quick-executing threads, then wait for them to
|
|
|
|
complete. */
|
|
|
|
for (i = 0; i < 1000; ++i)
|
|
|
|
{
|
|
|
|
for (j = 0; j < 256; ++j)
|
|
|
|
{
|
2006-10-17 15:52:53 +00:00
|
|
|
args[j] = i * 1000 + j;
|
|
|
|
pthread_create (&threads[j], &attr, thread_function, &args[j]);
|
2004-04-22 22:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < 256; ++j)
|
|
|
|
{
|
|
|
|
pthread_join (threads[j], NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_attr_destroy (&attr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|