开发者

Does thread-local mean thread safe?

开发者 https://www.devze.com 2023-01-18 02:20 出处:网络
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 loc

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. Al开发者_JS百科so, how do you even go about doing such a thing?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消