thread-local-storage

Is there a known size limit of the thread local storage in a prevalent modern OS?

妖精的绣舞 提交于 2021-02-07 14:39:27
问题 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

Is there a way to determine thread local storage model used by a library on Linux

筅森魡賤 提交于 2020-12-02 07:22:52
问题 Is there a way to query the TLS model of a shared library on Linux? (eg using ldd or some other tool). I am having a trouble with loading too many libraries with the "initial-exec" model and would like to determine for sure which of the third party libs use this model (so I can free up some slots eg by linking statically). This results in an error: dlopen: cannot load any more object with static TLS see this question. 回答1: I ran into this error myself, and while investigating it, I came on a

Is there a way to determine thread local storage model used by a library on Linux

こ雲淡風輕ζ 提交于 2020-12-02 07:22:29
问题 Is there a way to query the TLS model of a shared library on Linux? (eg using ldd or some other tool). I am having a trouble with loading too many libraries with the "initial-exec" model and would like to determine for sure which of the third party libs use this model (so I can free up some slots eg by linking statically). This results in an error: dlopen: cannot load any more object with static TLS see this question. 回答1: I ran into this error myself, and while investigating it, I came on a

Is there a way to call library thread-local init/cleanup on thread creation/destruction?

牧云@^-^@ 提交于 2020-01-04 07:45:10
问题 This question is similar to How to call a function on a thread's creation and exit? but more specific. In another multi-process shared memory project I used a combination of an __attribute__((constructor)) labeled library init routine, lazy initialisation for each thread, and robust futexes to make sure resources weren't leaked in the shared memory even if a sys admin chose to SIGKILL one of the processes using it. However futexes within the APIs are way too heavyweight for my current project

C++11: Nontrivial Thread Local Static Variable?

笑着哭i 提交于 2020-01-01 08:46:21
问题 I have a class X: class X { ... } I want to do this: void f() { thread_local static X x = ...; ... } (actually I'm using gcc so keyword is "__thread") but I can't because you can only have trivial thread_locals. What is the best work-around for this? If I do it this way: void f() { thread_local static X* p = 0; if (!p) p = new X(...); X& x = *p; ... } then: the destructor won't be called when thread exits unnecessary dynamic memory allocation. Update: Here is what I have so far: #include

Thread-local storage in kernel mode?

雨燕双飞 提交于 2020-01-01 04:43:09
问题 Is there a Thread-Local Storage (TLS) equivalent for kernel-mode drivers in Windows (Win32 to be exact)? What I try to achieve: Eventually from within my driver's dispatch routine it may call many other functions (there may be a deep callstack). I want to supply some context information specific to the request being processed. That is, I have some structure, pointer to which should be visible in all the called functions, without explicitly passing it as a parameter to every function. Using

about TLS Callback in windows

淺唱寂寞╮ 提交于 2019-12-30 06:37:13
问题 this is the test code #include "windows.h" #include "iostream" using namespace std; __declspec(thread) int tls_int = 0; void NTAPI tls_callback(PVOID, DWORD dwReason, PVOID) { tls_int = 1; } #pragma data_seg(".CRT$XLB") PIMAGE_TLS_CALLBACK p_thread_callback = tls_callback; #pragma data_seg() int main() { cout<<"main thread tls value = "<<tls_int<<endl; return 0; } build with Multi-threaded Debug DLL (/MDd) run result : main thread tls value = 1 build with Multi-threaded Debug (/MTd) run