#include #include #include #include #define MAX_THREAD 2000 typedef struct { int id; } parm; void *hello(void *arg) { parm *p=(parm *)arg; printf("Hello from node %d\n", p->id); return (NULL); } void createThreads(int n, pthread_attr_t *pthread_custom_attr) { int i; pthread_t *threads; parm *p; threads=(pthread_t *)malloc(n*sizeof(*threads)); p=(parm *)malloc(sizeof(parm)*n); for (i=0; i MAX_THREAD)) { printf ("The # of thread should between 1 and %d.\n",MAX_THREAD); exit(1); } if (n>2) STACKSIZE = atoi(argv[2]) * 1024; pthread_attr_init(&pthread_custom_attr); pthread_attr_getstacksize(&pthread_custom_attr, &stacksize); printf("Going to create %d threads with default stack size: %d bytes\n", n, stacksize); createThreads(n, &pthread_custom_attr); printf("----------------------------------------------\n"); pthread_attr_setstacksize(&pthread_custom_attr, STACKSIZE); pthread_attr_getstacksize(&pthread_custom_attr, &stacksize); printf("Going to create %d threads with stack size: %d bytes\n", n, stacksize); createThreads(n, &pthread_custom_attr); return 0; }