thread-local-storage

access thread_local variable in inline assembly

对着背影说爱祢 提交于 2019-12-05 19:54:18
I'm dealing with some C++ code that has an optimised version that uses inline assembly. The optimised version is exhibiting behaviour that is not thread safe, which can be traced to 3 global variables that are accessed extensively from inside the assembly. __attribute__ ((aligned (16))) unsigned int SHAVITE_MESS[16]; __attribute__ ((aligned (16))) thread_local unsigned char SHAVITE_PTXT[8*4]; __attribute__ ((aligned (16))) unsigned int SHAVITE_CNTS[4] = {0,0,0,0}; ... asm ("movaps xmm0, SHAVITE_PTXT[rip]"); asm ("movaps xmm1, SHAVITE_PTXT[rip+16]"); asm ("movaps xmm3, SHAVITE_CNTS[rip]"); asm

Code sequences for TLS on ARM

旧时模样 提交于 2019-12-05 08:34:20
The ELF Handling For Thread-Local Storage document gives assembly sequences for the various models (local exec/initial exec/general dynamic) for various architectures. But not ARM -- is there anywhere I can see such code sequences for ARM? I'm working on a compiler and want to generate code that will operate properly with the platform linkers (both program and dynamic). For clarity, let's assume an ARMv7 CPU and a pretty new kernel and glibc (say 3.13+ / 2.19+), but I'd also be interested in what has to change for older hw/sw if that's easy to explain. I don't exactly understand what you want.

Is it legal to initialize a thread_local variable in the destructor of a global variable?

蓝咒 提交于 2019-12-04 23:12:28
This program: #include <iostream> struct Foo { Foo() { std::cout << "Foo()\n"; } ~Foo() { std::cout << "~Foo()\n"; } }; struct Bar { Bar() { std::cout << "Bar()\n"; } ~Bar() { std::cout << "~Bar()\n"; thread_local Foo foo; } }; Bar bar; int main() { return 0; } Prints Bar() ~Bar() Foo() for me (GCC 6.1, Linux, x86-64). ~Foo() is never called. Is that the expected behaviour? ecatmur The Standard does not cover this case; the strictest reading would be that it is legal to initialize a thread_local in the destructor of an object with static storage duration, but it is illegal to allow the program

How to manage Thread Local Storage (TLS) when using TPL?

此生再无相见时 提交于 2019-12-04 18:19:53
问题 I want to store logging context information in TLS so that I can set a value at the entry point, and have that value available in all resulting stacks. This work well, but I also using TPL and the ThreadPool. The problem then becomes how to migrate TLS data to the other threads. I can do it all myself, but then I lose nice methods like Parallel.For. Is there some way to have TLS copied when using TPL? This will also apply to C# when it gets the await feature. Thanks, Erick 回答1: Typically,

The Cost of thread_local

送分小仙女□ 提交于 2019-12-04 16:17:26
问题 Now that C++ is adding thread_local storage as a language feature, I'm wondering a few things: What is the cost of thead_local likely to be? In memory? For read and write operations? Associated with that: how do Operating Systems usually implement this? It would seem like anything declared thread_local would have to be given thread-specific storage space for each thread created. 回答1: Storage space: size of the variable * number of threads, or possibly (sizeof(var) + sizeof(var*)) * number of

Using ThreadLocal in instance variables

好久不见. 提交于 2019-12-04 13:11:50
问题 Do Java ThreadLocal variables produce thread-local values if they are used as instance variables (e.g., in a method that generates thread-local objects), or must they always be static to do so? As an example, assume a typical scenario where several, expensive to initialize objects of a class that is not thread-safe, need to be instantiated in a single static initialization block, stored in static variables of a single class (e.g., in a Map data structure) and from then on used for intensive

thread-local storage overhead

不想你离开。 提交于 2019-12-04 05:46:41
Assume there is some not-reentrant function that uses global variables: int i; void foo(void){ /* modify i */ } And then, I want to use this function in multithreaded code, so I can change code this way: void foo(int i){ /* modify i */ } or, by using gcc __thread specifier, more simplier: __thread int i; void foo(void){ /* modify i */ } Advantages of the last is that I don't need to change another code which call foo(). My questions is, how much overhead of thread-local storage is? Is there some not obvious issues with TLS? Is there some overhead if I will modify TLS`ed variable via separate

No luck compiling __thread using ndk clang 3.4/3.5

≡放荡痞女 提交于 2019-12-04 05:18:12
问题 I am trying to use __thread in this small program without luck. Any idea if this TLS is supported in ndk 10c clang 3.4/3.5? The same program compiles fine with ndk gcc 4.8/4.9 and native clang/gcc compilers. Here is the program and compile line - __thread int counter; int main () { counter=20; return 0; } [armeabi] Compile++ thumb: test <= test.cpp /Users/padlar/android/android-ndk-r10c/toolchains/llvm-3.5/prebuilt/darwin-x86/bin/clang++ -MMD -MP -MF ./obj/local/armeabi/objs/test/test.o.d

How to initialize thread local variable in c++? [duplicate]

北城以北 提交于 2019-12-04 04:00:26
Possible Duplicate: C++11 thread_local in gcc - alternatives Is there any way to fully emulate thread_local using GCC's __thread? I wanted to use the c++11 thread_local to create and use thread_local variable but as it is not yet supported by gcc, I am using gcc specific __thread . The way I declared the variable is myClass { public: static __thread int64_t m_minInt; }; __thread int64_t myClass::m_minInt = 100; When I compile it, I get an error like error: ‘myClass::minInt’ is thread-local and so cannot be dynamically initialized How to properly do it? PS: gcc version: 4.6.3 You need to use

Thread-Local storage and iOS

我怕爱的太早我们不能终老 提交于 2019-12-04 03:11:09
问题 My understanding is that iOS does not support __thread . There is, obviously, a way to do this using pthread_setspecific . However, is there already a template class that has implemented this functionality? I'd ate to re-invent the wheel, especially as it won't be a simple piece of code to write. Any links would be hugely appreciated! Cheers 回答1: Foundation provides -[NSThread threadDictionary] . You can use this to store thread-local Objective-C objects, which could include an NSValue