Specifically I'm talking about Python. I'm trying to hack something (just a little) by seeing an object's value without ever passing it in, and I'm wondering if it is thread safe to use thread local to do that. Also, how do you even go about doing such a thing?
+3
A:
No -- thread local means that each thread gets its own copy of that variable. Using it is (at least normally) thread-safe, simply because each thread uses its own variable, separate from variables by the same name that's accessible to other threads. OTOH, they're not (normally) useful for communication between threads.
Jerry Coffin
2010-09-25 18:07:53
@Jerry - so, I could set a variable in module_x using `my_psuedo_global = threading.local()` and then somehow access it in module_y later, without breaking thread-saftey?
orokusaki
2010-09-25 18:12:53
Not really -- while you certainly could pass a value from one thread-local variable to another via a (pseudo-)global, you'd need to synchronize access to the global as you did so.
Jerry Coffin
2010-09-25 18:23:31