thread-local-storage

How to declare a variable as thread local portably?

雨燕双飞 提交于 2019-12-30 04:11:07
问题 C11 introduces the _Thread_local storage class specifier that can be used in combination with the static and extern storage class specifiers to declare a variable as thread local. The GNU C compiler suite implements a storage class specifier __thread with the same same semantics. Unfortunately I did not find any compiler (I tried gcc, clang and SUN studio) that actually implements the _Thread_local keywords. I currently use the following construct to declare a keyword thread_local : /* gcc

c++ thread-local storage clang-503.0.40 (Mac OSX)

落花浮王杯 提交于 2019-12-29 06:39:09
问题 After I declared a variable in this way: #include <thread> namespace thread_space { thread_local int s; } //etc. i tried to compile my code using 'g++ -std=c++0x -pthread [sourcefile]'. I get the following error: example.C:6:8: error: thread-local storage is unsupported for the current target static thread_local int s; ^ 1 error generated. If i try to compile the same code on Linux with GCC 4.8.1 whit the same flags, i get a functioning executable file. I'm using clang-503.0.40 (the one which

thread_local std::unique_ptr release not calling destructor

北城余情 提交于 2019-12-25 02:44:07
问题 Why isn't the destructor called in this code: #include <iostream> #include <thread> #include <memory> class base { public: base() { std::cout << "base()" << std::endl; } virtual ~base() { std::cout << "~base()" << std::endl; } base(const base&) = delete; base(base&&) = delete; base& operator=(const base&) = delete; base& operator=(base&&) = delete; }; class derived final : public base { public: derived() { std::cout << "derived()" << std::endl; } virtual ~derived() { std::cout << "~derived()"

How many bytes will a thread local variable in Rust use?

强颜欢笑 提交于 2019-12-24 07:16:28
问题 I want to use a thread local variable of type Option<usize> in a Rust library. How many bytes will this use per thread for crates that have a dependency on my library? I'm interested in Rust 1.39 and targeting Linux for three processors: amd64, x86 and arm32. 来源: https://stackoverflow.com/questions/58942482/how-many-bytes-will-a-thread-local-variable-in-rust-use

c++ static vs thread storage duration destruction order

北慕城南 提交于 2019-12-24 03:32:12
问题 Consider how in c++ there are these two storage duration (among others): static storage duration and thread storage duration.. Next consider this code: static MyClassA a; thread_local static MyClassB b; Additional pretend that "a" and "b" might not be in the same compilation unit. I "believe" that the destructor of "b" will be called before "a" as the thread storage duration will terminate first and only after that is complete will the static storage duration terminate and call the destructor

gcc / ld: overlapping sections (.tbss, .init_array) in statically-linked ELF binary

大城市里の小女人 提交于 2019-12-23 14:59:28
问题 I'm compiling a very simple hello-world one-liner statically on Debian 7 system on x86_64 machine with gcc version 4.8.2 (Debian 4.8.2-21): gcc test.c -static -o test and I get an executable ELF file that includes the following sections: [17] .tdata PROGBITS 00000000006b4000 000b4000 0000000000000020 0000000000000000 WAT 0 0 8 [18] .tbss NOBITS 00000000006b4020 000b4020 0000000000000030 0000000000000000 WAT 0 0 8 [19] .init_array INIT_ARRAY 00000000006b4020 000b4020 0000000000000010

dlopen: cannot load any more object with static TLS

可紊 提交于 2019-12-23 10:23:18
问题 I have a large mixed java/c++ application that loads multiple shared libs into java. It works fine on my Ubuntu 12.04 32-bit machine, but I'm having problems getting things to work on a Fedora 17 64-bit machine. Everything compiles fine, but when I try to run it I get: Exception in thread "main" java.lang.UnsatisfiedLinkError: /pathto/libmylib.so: dlopen: cannot load any more object with static TLS Any help is greatly appreciated! UPDATE: I've narrowed this down to a problem with PCL (point

thread-local static uniform_int_distribution, will it be recreated for different sets of min, max?

∥☆過路亽.° 提交于 2019-12-23 04:02:27
问题 In this answer on stackoverflow (answer #2) @remyabel recommends this template: #include <random> std::mt19937& prng_engine() { thread_local static std::random_device rd{}; thread_local static std::mt19937 engine{rd()}; // Or you can replace the two previous lines with: //thread_local static std::mt19937 // prng{std::random_device{}()}; return engine; } template<typename T> T getRandomNumberBetween(T Min, T Max) { thread_local static std::uniform_int_distribution<T> dist{Min, Max}; return

Why is thread local storage not implemented with page table mappings?

北城余情 提交于 2019-12-22 06:02:50
问题 I was hoping to use the C++11 thread_local keyword for a per-thread boolean flag that is going to be accessed very frequently. However, most compilers seem to implemented thread local storage with a table that maps integer IDs (slots) to the variable's address on the current thread. This lookup would happen inside a performance-critical code path, so I have some concerns about its performance. The way I would have expected thread local storage to be implemented is by allocating virtual memory

Using boost::thread_specific_ptr in a non-boost thread

て烟熏妆下的殇ゞ 提交于 2019-12-22 05:52:35
问题 I'm reading the documentation section for boost::thread_specific_ptr, and trying to parse this paragraph: Note: on some platforms, cleanup of thread-specific data is not performed for threads created with the platform's native API. On those platforms such cleanup is only done for threads that are started with boost::thread unless boost::on_thread_exit() is called manually from that thread. First, what is probably a pedantic point: I assume they meant to say boost::this_thread::at_thread_exit(