Boost logo

Boost :

From: Roland (roland.schwarz_at_[hidden])
Date: 2004-08-11 05:27:53

On Mon, 09 Aug 2004 11:42:44 +0200 Alexander Terekhov <terekhov_at_[hidden]> wrote:

> Roland wrote:
> >
> > While considering various ways to get rid of the remaining
> > intentional memory leak of the tss implementation, I came
> > upon the following question:
> >
> > How long may a thread access it's tss storage anyway?
> Process termination aside for a moment, as long as it can
> > I did not find anything in the documentation about the topic.
> >
> > Looking into the destructor of thread_specific_ptr reveals
> > ~thread_specific_ptr() { reset(); }
> The issue here is reuse of TSD keys. For keys without cleanup
> (null TSD destructor), implementations shall ensure that appls
> see nulls upon reuse. In the case of keys WITH cleanup (non-
> null TSD destuctors), it is the responsibility of appls to
> clear the slots (in all relevant threads) and perform cleanup
> prior to TSD key destruction.
> (Subject: Re: TSD key reuse)

This post mentions the necessity that ~thread_specific_ptr needs
to deallocate the slot.
Is this really necessary? I see two different areas of concern:
1) Process termination: Not really a need to free the native slot, since
the process is going away anyways. Also I think no current memory
debugging utility will bother with native slots.
2) DLL detachment: It is essential to free the native slot, since not
doing so prevents reuse. However this will be bad for connected
threads. There seems to exist some principal coupling between
the lifetime of a thread and lifetime of a DLL, which is not enforced
by the operating system.

> [...]
> > How is the situation for other libraries, say e.g. pthreads?
> > Are they allowed to run after main ended?
> Main (initial) *thread* is just a thread, nothing special.
> Main *function* is special. Return from main is just like
> calling exit() -- it evaporates all threads without
> any thread cleanup. OTOH, mere termination of main/initial
> thread (by means of pthread_exit() or thread cancellation),
> has no effect with respect to other threads.

This sounds interesting to me. It is really possible to use
pthread_exit() to exit the main thread?
And what happens then?
Are the global destuctors called? Or are they held off until
the last thread exited?


Boost list run by bdawes at, gregod at, cpdaniel at, john at