The problem is just the release of TLS after the thread is not used
I've been mulling over this lately, especially what happens if you use the
CRT on OS thread-pool threads (as used by QueueUserWorkItem, for example).
I've found a couple of newsgroup discussions covering this, and it seems
the general consensus is that it is safe if you link with the DLL version
of the CRT, because it has the cleanup code in its DLL_THREAD_DETACH
handler in DllMain.
So, I would venture to guess that if you link with the DLL CRT, none of
this is a problem. Does that ring true to you?
From MSDN
"To use thread pooling, the work items and all the functions they call must
be thread-pool safe. A safe function does not assume that thread executing
it is a dedicated or persistent thread. In general, you should avoid using
thread local storage and queuing asynchronous calls that require a
persistent thread, such as the RegNotifyChangeKeyValue function. However,
such functions can be queued to a persistent worker thread using
QueueUserWorkItem with the WT_EXECUTEINPERSISTENTTHREAD option."
If you follow this guideline, you won't have issues with your own code
because there will be no TLS to cleanup.
There is no mention of the CRT, so it should not matter either way (static
or dynamic) or it should have been mentioned along with the above
restrictions.
Could you post a link to the discussions you found regarding this? I'll take
a closer look.
--
Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"