Date: Tue, 25 Jan 2005 16:50:51 -0800 (PST) From: Yan Yu <yanyu@CS.UCLA.EDU> To: Jose Hidalgo Herrera <jose@hostarica.com> Cc: Julian Elischer <julian@elischer.org> Subject: Re: seg fault on kse_release () (fwd) Message-ID: <Pine.GSO.4.58.0501251639520.5349@panther.cs.ucla.edu> In-Reply-To: <1106698640.1383.3.camel@jose.hostarica.net> References: <Pine.GSO.4.58.0501241426470.2472@panther.cs.ucla.edu> <Pine.GSO.4.58.0501251028210.8888@panther.cs.ucla.edu> <41F6C27D.3040302@elischer.org> <Pine.GSO.4.58.0501251412590.22219@panther.cs.ucla.edu> <1106698640.1383.3.camel@jose.hostarica.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Cool, Thanks A LOT for looking into this! I appreciate it! after I reduce the BSIZE to 50k, it can create more than 10k threads before calloc error.. so i am going to drop this thread:) (just fyi, i use your prog on our machine w/ BSIZE =500k (~512M Ram), again i got SEG fault before the calloc error after it creates 913 threads, this number is repeatable.. so it is wierd.. as suggested by others, it might be a lib related prob., we may use a diff lib etc.. i am going to look into this later.. Thanks again! yan On Tue, 25 Jan 2005, Jose Hidalgo Herrera wrote: > This is my last try!, it worked for me, I reached a little more that > 1000 threads, then I got the calloc error. > :-) > > > > > > #include <pthread.h> > #include <stdlib.h> > #include <stdio.h> > #include <assert.h> > > #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); > } > > >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.58.0501251639520.5349>