LOTS of thanx for You answer! I will read the html about another ways
of serving many requests, but:
> Using this many threads is usually considered to be a Bad Idea (TM).
> Most likely you get the segfault because the default stacksize for each
> thread is 1MB or something sufficiently large to run your process out of
> virtual memory. Try reducing your VM limit (see ulimit in the bash
> docs) to 50MB -- this should cause you to get the segfault at a much
> smaller number of threads if this theory is correct.
> Thinking you need this many threads is usually the result of a design
> that could be significantly improved. Take a look at the ACE website
> www.cs.wustl.edu/~schmidt/ACE.html including the various tutorials about
> networking architectures and concurrency patterns. There are lots of
> good papers and interesting books referenced.
> There are also some errors, presumably introduced in order to simplify
> the example from something longer.
> 1. You loop testing the value of thread counter, which is never
> decremented.
yes, NOW this is true. this example is a CUTTED version of by program
- so, this is why seems to be a dead lock - but anyway it crashes
BEFORE sub-threads wake up
Quote:> 2. You should be joining with the threads, or creating them detached.
i have tried
result = pthread_attr_init(&tattr);
result = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED);
result = pthread_create(&child_id, &tattr, &entry_point, (int
*)thread_counter);
- but the same SEGM FAULT
Quote:> 3. If the threads are supposed to decrement thread_counter, accesses to
> that variable should be with a mutex locked, or using some atomic
> instruction (not thread_counter++).
why can not i use thread_counter--? is thread_counter =
thread_counter - 1
better in case of multithreading? i see no sence in blocking HERE (of
cause i use block in ather places with hashes or some BIG
structutres). Please write a little more details
Quote:> 4. If you *really*, *really*, need a huge number of threads, you should
> probably provide a smaller stacksize for each in the pthread_create
> call. But you almost certainly do not need this many.
I have 768Mb RAM, this test soft uses 10Mb OR LESS of RAM on my LINUX
2.4 BOX
No swap is EVER used.
I am sure i do NOT need 8Mb of stack, but i see no reason of SEGM
FAULT here
> Jeff
> ...
> > #define MAX_THREADS 1700
> > int thread_counter;
> > void *entry_point(void *);
> > int main() {
> > pthread_t child_id;
> > int result;
> > while(1) {
> > thread_counter++;
> > if(thread_counter>MAX_THREADS) {
> > break;
> > }
> > result = pthread_create(&child_id, NULL, &entry_point, (int
> *)thread_counter);
> > if(result==-1) {
> > printf("FATAL: error creating thread\n");exit(1);
> > }
> > if(thread_counter % 100==0) {
> > printf("Started %d threads...\n", thread_counter);
> > }
> > }
> > printf("Weating all threads to finish...\n");
> > while(thread_counter>0) {
> > sleep(1);
> > }
> return 0;
> > }
> > void *entry_point(void * thread_id) {
> > int counter, par, file_pos, pos;
> > char *cur_ip;
> > FILE *report;
> > sleep(10);
> > printf("wake\n");
> > }