From owner-freebsd-hackers@FreeBSD.ORG Wed Jan 26 00:17:21 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 82D3A16A4E0 for ; Wed, 26 Jan 2005 00:17:21 +0000 (GMT) Received: from mx.hostarica.com (www2.hostarica.com [196.40.45.74]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1715F43D45 for ; Wed, 26 Jan 2005 00:17:21 +0000 (GMT) (envelope-from jose@hostarica.com) Received: from localhost (localhost.hostarica.com [127.0.0.1]) by mx.hostarica.com (Postfix) with ESMTP id 259D4F696; Tue, 25 Jan 2005 18:27:27 -0600 (CST) Received: from localhost.localdomain (jose.hostarica.net [192.168.0.69]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by mx.hostarica.com (Postfix) with ESMTP id E2FDDF6A6; Tue, 25 Jan 2005 18:27:25 -0600 (CST) From: Jose Hidalgo Herrera To: Yan Yu In-Reply-To: References: <1106669661.9523.7.camel@jose.hostarica.net> <1106686056.4973.6.camel@jose.hostarica.net> <41F6C27D.3040302@elischer.org> Content-Type: text/plain Organization: Corp. Hostarica Date: Tue, 25 Jan 2005 18:17:20 -0600 Message-Id: <1106698640.1383.3.camel@jose.hostarica.net> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd 0.1 cc: freebsd-hackers@freebsd.org cc: Julian Elischer cc: jose@hostarica.com Subject: Re: seg fault on kse_release () (fwd) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: jose@hostarica.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jan 2005 00:17:21 -0000 This is my last try!, it worked for me, I reached a little more that 1000 threads, then I got the calloc error. :-) #include #include #include #include #define NUM_THREADS 5000 #define THREADS_IN_ONE_PROCESS 5 #define BSIZE 500000 static int cc; void *PrintHello(void *); pthread_mutex_t mtx; void CreateThread(int n, int myid) { int rc, t; unsigned long id; char * p; pthread_t threads[NUM_THREADS]; assert( n <= NUM_THREADS ); for(t=0;t < n;t++){ printf("id:%d Creating thread %d\n",myid,t); rc = pthread_create(&threads[t], NULL, PrintHello, NULL); if (rc){ printf("ERROR; return code from pthread_create() is %d\n", rc); } } pthread_mutex_lock(&mtx); p = (char *) calloc(BSIZE, sizeof(char) ); if ( p == NULL ) { pthread_mutex_unlock(&mtx); perror("calloc"); pthread_exit(NULL); } pthread_mutex_unlock(&mtx); while (1) { while (BSIZE <= (id = rand() / (RAND_MAX/BSIZE))); p[id] ++; } } void *PrintHello(void * threadid) { int * myid=NULL; pthread_mutex_lock(&mtx); myid=(int *)malloc(sizeof(int)); if (myid==NULL){ pthread_mutex_unlock(&mtx); perror("malloc"); pthread_exit(NULL); } *myid= cc++; pthread_mutex_unlock(&mtx); printf("\n%d: Hello World!\n", *myid); CreateThread(THREADS_IN_ONE_PROCESS,*myid); pthread_exit(NULL); } int main (int argc, char *argv[]) { pthread_mutex_init(&mtx, NULL); CreateThread(THREADS_IN_ONE_PROCESS,0); pthread_mutex_destroy(&mtx); }