Memory visibility in C++ concurrency (no data race)

我只是一个虾纸丫 提交于 2019-12-06 05:05:18

is this safe to use the copy of the shared_ptr if there is no synchronization in Object class at all

Yes, std::shared_ptr is synchronized so that it's reference count is thread safe. Read/write synchronization of the object it points to, however, is up to you.

Edit after question edited:

Is the executor thread guaranteed to see the value 5?

No, this is exactly the same as passing a raw pointer to your myExecutor thread.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!