问题
When I use thread_local
, _Thread_local
, __thread
, or __declspec(thread)
, the compiler seems to allocate a thread local storage upon thread creation and store the address in the fs
or gs
register in an x86 derived system.
In this context, is there something like 'thread local storage overflow'?
回答1:
There are limits. Each system will be different, but on Windows, there is a limited data section which is mapped thread specifically. The size of this section is limited.
Older versions of windows used this directly, and would fail when new items were created.
Last time I checked on Windows 7+, this had gone (OS uses 1 slot for the whole DLL - as a redirection to a thread local map), but there was a different limitation, which limited the number of unique slots available. Each DLL loaded used a slot, and thus there was a limit on the number of DLLs which could use thread local storage.
See also wikipedia : thread local storage
来源:https://stackoverflow.com/questions/32310208/is-there-a-known-size-limit-of-the-thread-local-storage-in-a-prevalent-modern-os