When using the explicit tss_
functions there is a limit of 1024 TSS indices per process, these are not the same indices used for the Fls*
functions, the Tls*
functions, or _Thread_local
“implicit” TLS variables. If you use any <threads.h>
functions (not just the TSS functions) and you use the static runtime then you will use at least one implicit TLS index (the ones used for _Thread_local
), even if you don’t otherwise use implicit TLS. This is because we need to enable TLS callbacks, which causes the loader to allocate such an index. If this is a problem (for example because of the loader gymnastics that are required to dynamically load such modules) let us know, or just use the dynamic runtime. If you use the tss_
functions then additionally you will use one dynamic TLS index (the same ones used by TlsAlloc
), you will only use one, no matter how many tss_t
s you create. Threads will only spend time processing TSS destructors at thread exit if a TSS index with an associated destructor was ever set on that thread. When you create the first tss_t
a table of destructors is allocated and when you use tss_set
for the first time on a particular thread a per-thread table is allocated. Memory usage scales with the number of threads that use the C11 TSS functionality, not the total number of threads in the process. The destructor table is 8KiB (4KiB on 32-bit platforms) and each per thread table is 8209 bytes (4105 bytes on 32-bit platforms). These performance and memory characteristics may change in the future.
Because <threads.h>
is a new feature and we want the implementation to be able to change and improve over time, it’s shipped as a new satellite DLL of vcruntime: vcruntime140_threads.dll
and vcruntime140_threadsd.dll
. If you use the dynamic version of the Visual C++ runtime (/MD
or /MDd
), and you use the new threads facilities, then you need to either redistribute this file with your app, or redistribute a Visual C++ runtime redist that is new enough to contain these files. If you don’t touch the C11 threads functionality then your app won’t depend on anything in this DLL and it will not be loaded at all.
In Visual Studio 2022 version 17.6 we added a host of new ARM64 optimizations. In this 2nd edition of our blog, we will highlight some of the performance improvements to ...