简体   繁体   English

复制 object 的引用或将其传递给方法/构造函数是线程安全的吗?

[英]Copy the reference of an object or pass it in a method/constructor is thread safe?

I have an object that is shared in read/write between threads.我有一个 object 在线程之间的读/写中共享。

Assuming that the synchonization is correctely done, if A is the object previously initialized when no threads are running, when they start working is thread-safe do:假设同步正确完成,如果 A 是之前在没有线程运行时初始化的 object,那么当它们开始工作时是线程安全的:

Object B = A;

DoSomething(A);

? ?

References can safely be shared;可以安全地共享参考; however, access to the actual object may require synchronization.但是,访问实际的 object 可能需要同步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM