Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2006-07-20 10:18:32


"Peter Dimov" <pdimov_at_[hidden]> writes:

> Anthony Williams wrote:
>> Can we have a call to TlsFree in on_process_exit, so we don't leak
>> the TLS slot either?
>
> It's better not to. We don't leak a TLS slot because TLS slots are per
> process. When the process is terminated by the OS, all of its TLS slots are
> "reclaimed" (more precisely, they simply cease to exist.)
>
> So we gain nothing because the lack of TlsFree is not observable.

The same could be said of just about everything that the OS cleans up ---
handles, memory, etc. In some circumstances, it *is* best not to do the clean
up, to avoid potential race conditions with the clean up code and uses; I just
want to ensure this has been thought about, as it's better to explicitly free
stuff if you can.

> On the other hand, if on_process_exit is called when some threads are still
> running, TlsFree'ing the slot will make it impossible for these threads to
> clean up after themselves since they won't be able to access their cleanup
> handler lists. This can be observable if their cleanup handlers have visible
> side effects.

on_process_exit is called when the module is unloaded. If there are any
threads running at that point which are referencing code in that module
(e.g. because they use boost thread cleanup handlers), they have bigger
problems than the fact that the TLS slot has been freed --- the whole module
is being unloaded.

The TLS slot in question is internal to tss_hooks.cpp, and is only used by
at_thread_exit/on_thread_exit. If the module is being unloaded (which is why
on_process_exit is being run), then on_thread_exit will no longer be
accessible, so the clean up handlers won't be run anyway.

Anthony

-- 
Anthony Williams
Software Developer
Just Software Solutions Ltd
http://www.justsoftwaresolutions.co.uk

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