thread-local

Multiple independent embedded Python Interpreters on multiple operating system threads invoked from C/C++ program

人走茶凉 提交于 2019-11-27 01:33:16
问题 Embedding Python interpreter in a C/C++ application is well documented. What is the best approach to run multiple python interpreter on multiple operating system threads (i.e. one interpreter on one operating system thread within the same process) which are invoked from the C/C++ application? Such applications may also have problems related to memory fragmentation and limitations of Py_Finalize(). One such approach can be the following: Python thread and hence GIL disabled in pyconfig.h to

How to clean up ThreadLocals

喜你入骨 提交于 2019-11-27 00:17:12
Does any one have an example how to do this? Are they handled by the garbage collector? I'm using Tomcat 6. The javadoc says this: "Each thread holds an implicit reference to its copy of a thread-local variable as long as the thread is alive and the ThreadLocal instance is accessible; after a thread goes away, all of its copies of thread-local instances are subject to garbage collection (unless other references to these copies exist). If your application or (if you are talking about request threads) container uses a thread pool that means that threads don't die. If necessary, you would need to

How to initialize ThreadLocal objects in Java

橙三吉。 提交于 2019-11-26 23:14:27
问题 I'm having an issue where I'm creating a ThreadLocal and initializing it with new ThreadLocal . The problem is, I really conceptually just want a persistent list that lasts the life of the thread, but I don't know if there's a way to initialize something per-thread in Java. E.g. what I want is something like: ThreadLocal static { myThreadLocalVariable.set(new ArrayList<Whatever>()); } So that it initializes it for every thread. I know I can do this: private static Whatever getMyVariable() {

Why is using thread locals in Django bad?

不想你离开。 提交于 2019-11-26 21:51:14
I am using thread locals to store the current user and request objects. This way I can have easy access to the request from anywhere in the programme (e.g. dynamic forms) without having to pass them around. To implement the thread locals storage in a middleware, I followed a tutorial on the Django site: http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser?version=18 This document has since been modified to suggest avoiding this technique: http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser?version=20 From the article: From a design point of view, threadlocals are

ThreadLocal & Memory Leak

会有一股神秘感。 提交于 2019-11-26 19:21:52
It is mentioned at multiple posts: improper use of ThreadLocal causes Memory Leak. I am struggling to understand how Memory Leak would happen using ThreadLocal . The only scenario I have figured out it as below: A web-server maintains a pool of Threads (e.g. for servlets). Those threads can create memory leak if the variables in ThreadLocal are not removed because Threads do not die. This scenario does not mention "Perm Space" memory leak. Is that the only (major) use case of memory leak? PermGen exhaustions in combination with ThreadLocal are often caused by classloader leaks . An example:

Propagating ThreadLocal to a new Thread fetched from a ExecutorService

佐手、 提交于 2019-11-26 19:14:58
问题 I'm running a process in a separate thread with a timeout, using an ExecutorService and a Future (example code here) (the thread "spawning" takes place in a AOP Aspect). Now, the main thread is a Resteasy request. Resteasy uses one ore more ThreadLocal variables to store some context information that I need to retrieve at some point in my Rest method call. Problem is, since the Resteasy thread is running in a new thread, the ThreadLocal variables are lost. What would be the best way to

What does the thread_local mean in C++11?

五迷三道 提交于 2019-11-26 17:00:57
I am confused with the description of thread_local in C++11. My understanding is, each thread has unique copy of local variables in a function. The global/static variables can be accessed by all the threads (possibly synchronized access using locks). And the thread_local variables are visible to all the threads but can only modified by the thread for which they are defined? Is it correct? paxdiablo Thread-local storage duration is a term used to refer to data that is seemingly global or static storage duration (from the viewpoint of the functions using it) but in actual fact, there is one copy

Purpose of ThreadLocal? [duplicate]

两盒软妹~` 提交于 2019-11-26 11:48:31
问题 This question already has an answer here: When and how should I use a ThreadLocal variable? 24 answers The purpose of ThreadLocal as given here states that the variable is local to any Thread accessing an object containing the ThreadLocal variable. What difference does it make, in having a ThreadLocal variable as a member of a class and then making it local to a Thread, rather than having a local variable to the Thread itself? 回答1: A thread is a unit of execution and so multiple thread can

What is “thread local storage” in Python, and why do I need it?

百般思念 提交于 2019-11-26 10:16:00
问题 In Python specifically, how do variables get shared between threads? Although I have used threading.Thread before I never really understood or saw examples of how variables got shared. Are they shared between the main thread and the children or only among the children? When would I need to use thread local storage to avoid this sharing? I have seen many warnings about synchronizing access to shared data among threads by using locks but I have yet to see a really good example of the problem.

Why is using thread locals in Django bad?

扶醉桌前 提交于 2019-11-26 06:29:14
问题 I am using thread locals to store the current user and request objects. This way I can have easy access to the request from anywhere in the programme (e.g. dynamic forms) without having to pass them around. To implement the thread locals storage in a middleware, I followed a tutorial on the Django site: http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser?version=18 This document has since been modified to suggest avoiding this technique: http://code.djangoproject.com/wiki