Subj : Re: Main thread going away but worker threads executing? To : comp.programming.threads From : David Schwartz Date : Mon Jul 18 2005 06:36 pm "doug" wrote in message news:cOWCe.154383$Vo6.34257@fe3.news.blueyonder.co.uk... > "David Schwartz" wrote in message > news:dbguov$gee$1@nntp.webmaster.com... >> The C language has no support for threads. But every threading >> standard I know of implements fully symettric threads where the "main >> thread" is in no way special. > Is that right? I may be mishtaken, but if (e.g. on linux, pthreads) my > main() exits while other threads are running I think the program as a > whole does die. Correct. Returning from 'main' is defined to terminate the process. > If I call pthread_exit() from the main() thread, the program continues > until all threads exit. Right. > Docs (from HP, so appears AIX uses same model. I used solaris a while > back, thinkg it does same) Yes, this is standard behavior. Returning from 'main' has always been defined as terminating the process and returning the value you returned. > An implicit call to pthread_exit() is made when a thread returns from its > start routine. The function's return value serves as the thread's exit > status (see pthread_create(3T)). If the main thread returns from main() > without calling pthread_exit(), the process will exit using the return > value from main() as the exit status. If the main thread calls > pthread_exit(), the process will continue executing until the last thread > terminates or a thread calls exit(). After the last thread in the process > terminates, the process will exit with an exit status of zero. Right. This isn't because the thread running 'main' is special, it's because of the code that it runs when you return from 'main'. This code could, in principle, be run by any thread (by calling an 'exit' function). DS .