Click to See Complete Forum and Search --> : Thread Shouldn't Terminate (Urgent )


majidpics
12-25-2002, 04:48 AM
tell me what should i do


i am creating thread from main(), and it terminates when the main returns, I have also used pthread_init_attr with DETACHED option. i dont want to use pthread_join bcz i dont want to stop main() execution flow. I want that main() should return but thread should not terminate.

Spawn913
12-25-2002, 11:39 PM
can you post your thread function so we can check why your thread exits?

majidpics
12-26-2002, 01:23 AM
check the attached code n tell me what i am doing

Spawn913
12-26-2002, 03:10 AM
The line:

strcpy(recv_file_name,(char_data+1));

probably causes your thread to terminate with a SEG FAULT.

You did not allocate space for recv_file_name before you called the strcpy, causing the SEG FAULT.

you can either re-declare recv_file_name as a character array (which can hold up to BSIZE bytes), or better yet, allocate it via malloc().

I haven't tested your code, but that's what I see as a potential problem source so far.

Stuka
12-26-2002, 01:52 PM
<edit>I really oughta read before posting</edit>
majidpics: when main() returns, the process is going to exit. This will kill all threads in the process. If you want your main() to exit but your server to run, you'll have to use fork() and exec().

Spawn913
12-26-2002, 09:18 PM
<edit>I really oughta read before posting</edit>

*grin* Right.