Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2004-08-11 11:24:34

Roland wrote:
> >
> > (Subject: Re: TSD key reuse)
> This post mentions the necessity that ~thread_specific_ptr needs
> to deallocate the slot.
> Is this really necessary?

Windows zaps the slots asynchronously if you do TlsFree.

<quote author=Neill Clift [MSFT]>

we do cross thread clearing of tls slots when its deleted by one


This is needed for thread_specific_ptr< T, no_cleanup > objects.

> 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.

The entire application shall stop using the DLL by the time it
unloads it. "dll_fini" will deallocate the slots. Now see above.
Having "thread insensible TSD dtros" wouldn't hurt either...

> >
> > [...]
> > > 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?

Yes. You can also cancel it.


is a shortcut for


See also

> And what happens then?

Main/initial thread terminates.

> Are the global destuctors called?

Only if main/initial is the last thread.

> Or are they held off until
> the last thread exited?



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