views:

54

answers:

1

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
@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
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