thread-local

How to create a thread local variable inside of a Rust struct?

空扰寡人 提交于 2020-07-23 09:08:27
问题 I need a thread local variable, ideally stored in a struct which currently stores most of my program's global state. The first way I can see to do this is to use the thread_local! macro, however I would like to keep this thread local within my state struct. The second way I can see to achieve this is to have a HashMap<Thread,MyThreadLocalData> or similar between threads and the value of my thread local variable(s). I would then have a getter which uses thread::current to lookup the

Using C++11 thread_local with other parallel libraries

[亡魂溺海] 提交于 2020-05-29 02:43:46
问题 I have a simple question, can C++11 thread_local be used with other parallel models. For example, can I use it within a function while using OpenMP or Intel TBB to parallel the tasks. Most such parallel programming models hide hardware threads behind higher level API. My instinct is that they all have to map their task schedulers into hardware threads. Can I expect that C++11 thread_local will have expected effect. A simple example is, void func () { static thread_local some_var = init_val;

spring security strategy MODE_INHERITABLETHREADLOCAL. Why?

北城余情 提交于 2020-01-16 01:08:14
问题 I understand how and what happens when we use MODE_THREADLOCAL and MODE_INHERITABLETHREADLOCAL in Spring Security Strategy. What I don't understand is, why would someone use MODE_THREADLOCAL over MODE_INHERITABLETHREADLOCAL. Is there a memory impact with using one over the other. If so, is it significant enough? What is a typical business/functional usecase for using MODE_INHERITABLETHREADLOCAL? Any performance different with using one over the other? 回答1: The memory impact of using the two

thread_local member variable construction

…衆ロ難τιáo~ 提交于 2020-01-13 09:33:46
问题 I'm facing some strange behavior with thread_local and not sure whether I'm doing something wrong or it's a GCC bug. I have the following minimal repro scenario: #include <iostream> using namespace std; struct bar { struct foo { foo () { cerr << "foo" << endl; } int i = 42; }; static thread_local foo FOO; }; static thread_local bar::foo FREE_FOO; thread_local bar::foo bar::FOO; int main() { bar b; cerr << "main" << endl; // cerr << FREE_FOO.i << endl; cerr << b.FOO.i << endl; return 0; } With

Is ThreadLocal safe to use with Tomcat NIO Connector

一世执手 提交于 2020-01-12 07:47:11
问题 This just came to mind when testing the Tomcat NIO connector during my load tests. I make use of ThreadLocal's additionally I use Spring, which I know in several places it also makes use of it. Since the NIO connector does not have a thread per connection, I worry that it may result in very hard to find bugs if a ThreadLocal object was shared with another thread before it had been cleaned up. However, I assume that this is not an issue as it is not a documented warning that I could find, nor

thread_local variables initialization

南笙酒味 提交于 2020-01-05 08:28:19
问题 I know this is a very basic question but I wasn't able to find a simple answer. I'm writing a program in which I need some variables to be thread_local . From my understanding this means that those variables are "like global variables" but each thread will have its own copy. I've put these variables in a dedicated namespace called utils inside a header file called Utilities.hpp in this way: // Utilities.hpp namespace utils { extern thread_local int var1; extern thread_local int var2; extern

Thread local data in linux kernel module

橙三吉。 提交于 2020-01-02 04:24:05
问题 Is it possible to create thread local data in a linux kernel module? I need to store some data for each process/thread calling my module. Is there an easy way of using thread local data, or do I have to resort to writing a hash map which uses the pid of the current process as a key? 回答1: Assuming the interface to you kernel module is a character device driver, then you have a private_data field in the file struct (which is analogous to user space file descriptor) exactly for that. Just

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

ThreadLocal - using as context information for REST API with spring-boot

試著忘記壹切 提交于 2019-12-31 05:41:12
问题 I have some spring-boot application (it exposes rest api). The mentioned REST API is secured by spring-security . Everything is fine, however now I need to set context for servicing request. Setting context is about choosing datasource in depends on user context. The key is that RoutingDataSource need to use this context. (This context must be set directly after authenticating request due to other causes, I have also other thread which use RoutingDataSource, but no invoked by request (no user

ThreadLocal - using as context information for REST API with spring-boot

给你一囗甜甜゛ 提交于 2019-12-31 05:41:07
问题 I have some spring-boot application (it exposes rest api). The mentioned REST API is secured by spring-security . Everything is fine, however now I need to set context for servicing request. Setting context is about choosing datasource in depends on user context. The key is that RoutingDataSource need to use this context. (This context must be set directly after authenticating request due to other causes, I have also other thread which use RoutingDataSource, but no invoked by request (no user