|
Boost : |
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2004-08-11 11:24:34
Roland wrote:
[...]
> > http://google.com/groups?selm=406ECF36.226C8B99%40web.de
> > (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.
http://groups.google.com/groups?selm=3f5d1aee%241%40news.microsoft.com
<quote author=Neill Clift [MSFT]>
we do cross thread clearing of tls slots when its deleted by one
thread.
</quote>
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.
Right.
> 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.
Right.
> 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.
pthread_exit(PTHREAD_CANCELED);
is a shortcut for
pthread_cancel(pthread_self());
pthread_testcancel();
See also
http://www.codesourcery.com/archives/c++-pthreads/msg00005.html
> 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?
Yes.
regards,
alexander.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk