From owner-freebsd-threads@FreeBSD.ORG Mon Jan 24 22:25:39 2005 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D0E3D16A4CE for ; Mon, 24 Jan 2005 22:25:39 +0000 (GMT) Received: from panther.cs.ucla.edu (Panther.CS.UCLA.EDU [131.179.128.25]) by mx1.FreeBSD.org (Postfix) with ESMTP id A822343D1D for ; Mon, 24 Jan 2005 22:25:39 +0000 (GMT) (envelope-from yanyu@CS.UCLA.EDU) Received: from localhost (yanyu@localhost)j0OMPdJ08053 for ; Mon, 24 Jan 2005 14:25:39 -0800 (PST) Date: Mon, 24 Jan 2005 14:25:39 -0800 (PST) From: Yan Yu To: freebsd-threads@freebsd.org Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: seg fault on kse_release () X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jan 2005 22:25:39 -0000 Hi, all, I have a newbie Q: I am trying to use creating large number of threads and allocting memory to stress the system. My user program causes SEG fault in the kernel code, kse_release () in kern_kse.c. the stack when the SEG fault happens are: #0 0x08064e54 in kse_release () #1 0x080531c4 in kse_sched_single () #2 0x00000000 in ?? () My simple program is: I have a simple function to create threads: #define NUM_THREADS 5000 #define THREADS_IN_ONE_PROCESS 5 #define BSIZE 500000 static int cc; void CreateThread(int n) { assert( n <= NUM_THREADS ); pthread_t threads[NUM_THREADS]; int rc, t; for(t=0;t < n;t++){ printf("#%d: Creating thread %d\n", cc, t); cc++; rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t); if (rc){ printf("ERROR; return code from pthread_create() is %d\n", rc); } } unsigned long id; char * p = (char *) calloc(BSIZE, sizeof(char) ); if ( p == NULL ) { fprintf(stderr, "calloc error\n"); } while (1) { while (BSIZE <= (id = rand() / (RAND_MAX/BSIZE))); p[id] ++; } } void *PrintHello(void *threadid) { printf("\n%d: Hello World!\n", threadid); CreateThread(THREADS_IN_ONE_PROCESS); pthread_exit(NULL); } int main (int argc, char *argv[]) { CreateThread(THREADS_IN_ONE_PROCESS); } The SEG fault happens after creating nearly 5000 threads. and I use the default pthread.h coming w/ freeBSD 5.3 #define PTHREAD_KEYS_MAX 256 #define PTHREAD_STACK_MIN (1 << 22) #define PTHREAD_THREADS_MAX ULONG_MAX Any idea on what might happen? Many Thanks! yan