Subj : Re: Strange behaviour To : comp.programming.threads From : Loic Domaigne Date : Tue Apr 19 2005 11:46 pm Hello Sunglo, > I have the following simple code (I know it's ugly, and many things are > missing, like error checks, etc.): > #include > #include > #include > #include > > #define THREADS 5 [snip] This code looks fine, actually. > I'm using linux 2.6 with NPTL. On which distro? > When this code runs, sometimes it > executes all the threads (ie, the messages from main() *AND* those from > the threads are printed, and the process waits about 5 secs. before > terminating), some other times it terminates immediately (only the > messages from main() are printed, and then it terminates). It almost > seems that, under certain conditions, the call to pthread_exit() from > main() terminates the whole process. Did you got that behavior with LinuxThreads? (export the environment variable LD_ASSUME_KERNEL to 2.4.19 before executing your process). > I believe that calling pthread_exit() from main() should not terminate > the whole process...unless, perhaps, at the time main() calls > pthread_exit(), no other thread has actually been created, so, being > main() the only thread, pthread_exit() terminates the process? (just a > guess, I hope you have some better explanation). Seems to be an issue in the NPTL you are using. Cheers, Loic. .