This is the mail archive of the
pthreads-win32@sourceware.cygnus.com
mailing list for the pthreas-win32 project.
Re: [pthread-win32] RE: pthread_exit bug ?
- To: Milan Gardian <mg@tatramed.sk>
- Subject: Re: [pthread-win32] RE: pthread_exit bug ?
- From: Tristan Savatier <tristan@mpegtv.com>
- Date: Thu, 02 Sep 1999 03:55:30 -0700
- CC: pthreads-win32@sourceware.cygnus.com
- Organization: MpegTV
- References: <000301bef52e$f59e5e10$440b10ac@leibinger.freinet.de>
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);
> }
most of the time it is not practical to return from
main(). this is why the exit() routine was invented.
you can call exit() from some other routine called
directly or indirectly by main().
So the question becomes: is there any difference between
(a')
int main(void)
{
//Do some threading stuff...
exit (24);
}
and...
>
> (b)
> void main(void)
> {
> //Do some threading stuff...
> pthread_exit(24);
> }
According to my book "Multithreaded
Programming with PThread" by Bil Lewis and Daniel J.Berg,
yes, there is a difference: they write that if the last thread
calls pthread_exit(n), then exit(0) is called (regardless
of n).
(b) is therefore equivalent to
int main(void)
{
//Do some threading stuff...
exit (0);
^^^^^^^^
}
>
> >From the rather ideological reasons :) I prefer the (a) version, but will
> gladly learn if there's a point in the (b) version.
Again, I don't know if the authors of my book are write, and I do not
have the official pthread standard documents.
-t