Re: I can't create thread more than 256 on Redhat 9
From: Waldek Hebisch (hebisch_at_math.uni.wroc.pl)
Date: 01/07/04
- Next message: David Konerding: "Re: I can't create thread more than 256 on Redhat 9"
- Previous message: RayL: "OpenCMS vs. WebGUI"
- In reply to: Kihong Lee: "Re: I can't create thread more than 256 on Redhat 9"
- Next in thread: Kihong Lee: "Re: I can't create thread more than 256 on Redhat 9"
- Reply: Kihong Lee: "Re: I can't create thread more than 256 on Redhat 9"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 7 Jan 2004 14:42:21 GMT
Kihong Lee (sisapinusa@yahoo.com) wrote:
: hebisch@math.uni.wroc.pl (Waldek Hebisch) wrote in message news:<btej3d$jaj$1@panorama.wcss.wroc.pl>...
: > It looks that each thread takes 8MB of virtual memory for the stack.
: > So IMHO you are running out of virtual memory. So either set lower
: > limit on treads stack size (I do not know how, but that is a standard
: > parameter) or get 64-bit machine.
: You mean, I might have to modify kernel header file to adjust stack
: size, and do kernel complie again, right?
No, it is a parameter in the thread library. On RedHat 9 (nptl) the following
program went up to 4091 threads (on 512 MB machine):
/* compile with: gcc -lpthread -o thread-limit thread-limit.c */
/* originally from: http://www.volano.com/linuxnotes.html */
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#define MAX_THREADS 10000
int i;
void run(void) {
char c;
if (i < 10)
printf("Address of c = %u KB\n", (unsigned int) &c / 1024);
sleep(60 * 60);
}
int main(int argc, char *argv[]) {
int rc = 0;
pthread_t thread[MAX_THREADS];
pthread_attr_t attribites;
pthread_attr_init(&attribites);
/* Set low stack limit to allow more threads */
pthread_attr_setstacksize (&attribites, 64*1024);
printf("Creating threads ...\n");
for (i = 0; i < MAX_THREADS && rc == 0; i++) {
rc = pthread_create(&(thread[i]), &attribites, (void *) &run, NULL);
if (rc == 0) {
pthread_detach(thread[i]);
if ((i + 1) % 100 == 0)
printf("%i threads so far ...\n", i + 1);
}
else
printf("Failed with return code %i creating thread %i.\n",
rc, i + 1);
}
exit(0);
}
It seems that earlier threads libraries (linuxthreads) may ignore
stack settings, then you would be forced to recompile `linuxthreads'
(probably the whole glibc).
--
Waldek Hebisch
hebisch@math.uni.wroc.pl
- Next message: David Konerding: "Re: I can't create thread more than 256 on Redhat 9"
- Previous message: RayL: "OpenCMS vs. WebGUI"
- In reply to: Kihong Lee: "Re: I can't create thread more than 256 on Redhat 9"
- Next in thread: Kihong Lee: "Re: I can't create thread more than 256 on Redhat 9"
- Reply: Kihong Lee: "Re: I can't create thread more than 256 on Redhat 9"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|