Date: Sun, 1 Feb 2004 01:12:12 -0500 From: Craig Rodrigues <rodrigc@crodrigues.org> To: freebsd-threads@freebsd.org Subject: pthread_create() blocks if maxthreads reached? Message-ID: <20040201061212.GA6349@crodrigues.org>
next in thread | raw e-mail | index | archive | help
Hi, I wrote the following small test program to spawn a large number of threads. ================================================================== #include <sys/types.h> #include <sys/select.h> #include <pthread.h> #include <stdio.h> #define NUM 100000 void *thr(void *p) { select(0, NULL, NULL, NULL, NULL); return p; } int main() { pthread_t t[NUM]; int ret=0; int i; for(i=0; ; ++i) { printf("Entering pthread_create...\n"); ret = pthread_create(&t[i], NULL, thr, NULL); printf("Left pthread_create...\n"); if( ret != 0 ) { printf("%d %s\n", ret, strerror(ret)); break; } } printf("Max threads reached at: %d\n", i); return 0; } ============================================================== If I link this program with -lthr or -lc_r, the program will terminate. If I link with -lpthread, the program seems to block in the pthread_create() call, instead of returning EAGAIN (to indicate that a new thread cannot be created due to hitting some system limit). Any ideas on this? Thanks. -- Craig Rodrigues http://crodrigues.org rodrigc@crodrigues.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040201061212.GA6349>