|The constructor starts a
|Notice the use of _beginthreadex
– you are not supposed to use Windows API CreateThread in Windows
programs (go figure!). Here’s what Jeff Richter told me:
There are not a lot of C-Runtime functions that require TLS. The best way to know is to examine the C-Runtime source code which ships with all copies of Visual C++. Certainly strtok, asctime, and gmtime require it. I also know that errno is a macro that access TLS. So, any function that sets errno is also using TLS.
You should just use _beginthreadex instead of CreateThread - period. There is no reason not to. However, if you use CreateThread AND dynamically-link to the C-Runtime DLL, then the TLS will NOT leak. But, this ties the freeing of TLS to your build process which is always a bad idea.Using _beginthread means that TLS will get freed regardless of how you build your app.
Of course, if the thread is terminated (as opposed to exits) for some reason, the TLS will leak.