Subj : Re: Main thread going away but worker threads executing? To : comp.programming.threads From : doug Date : Tue Jul 19 2005 12:19 am "David Schwartz" wrote in message news:dbguov$gee$1@nntp.webmaster.com... > > "Kev" wrote in message > news:Pine.SOL.4.63.0507181045340.12475@conquest.OCF.Berkeley.EDU... > >> I have been under the impression that this behavior is expected in C# but >> that the opposite is true in C. (If the main thread dies, everything >> dies.) > > 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. If I call pthread_exit() from the main() thread, the program continues until all threads exit. Docs (from HP, so appears AIX uses same model. I used solaris a while back, thinkg it does same) 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. > DS > > .