Boost logo

Boost :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2005-09-14 06:25:52


Jason Hise wrote:

> Quick question though: Are global variables
>destroyed only when the last thread exits (ensuring that the point of
>destruction of all globals is atomic), or do they die when the main
>thread exits?
>
>
There is no single answer to this as this will depend on platform.
On windows e.g. it is easily possible to create a thread by the native Win32
API call CreateThread that even will survive when your main has exited
and all global cleanup handlers are done (including global destructor
calls).
When it comes to process exit of course threads still running are simply
extinguished (Without any chance to run cleanup handlers, not even
the thread exit callback will help there).
So it is entirely up to the application programmer when the last thread
finishes.

If e.g. someone starts a thread from a global constructor (which currently
is deemed bad practice), and ended from its destrutor, the time when this
thread will actually die is simply unspecified.

Regards,
Roland


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk