This is the mail archive of the pthreads-win32@sourceware.cygnus.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [pthread-win32] RE: pthread_exit bug ?


Milan Gardian wrote:
> 
> [snip]
> > My program creates several threads.  At termination,
> > each thread (except the main thread) terminates by calling
> > pthread_exit, then the main thread terminates by
> > calling pthread_exit (at this point, all my threads
> > are terminated, therefore the process should disapear).
> 
> (This note does not try to diminish the meaning of the reported bug)
> Q: Is there a reason to use pthread_exit from the main thread? A special
> functionality prehaps? Specifically, I would like to know if there's some
> difference between these two code snips:
> 
> (a)
> int main(void)
> {
>     //Do some threading stuff...
>     return (24);
> }
> 
> (b)
> void main(void)
> {
>     //Do some threading stuff...
>     pthread_exit(24);
> }

Note also another big difference between those two cases,
according to my book:

When main() "falls off the bottom" i.e. returns,
the main thread makes an implicit call to exit(),
also killing the process.

When any other thread "falls off the bottom" of its
initial function, it implicitely calls pthread_exit()
exiting only that one thrad.

In the special case where the main thread calls pthread_exit(),
that thread exits but does NOT call exit(), and the
process continues.

Finally, if all the [main and user-created] threads exit,
the thread library will detect that and call exit() itself
to terminate the process.

-t

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]