Is it wise to access read-only data from multiple threads simultaneously?

*爱你&永不变心* 提交于 2019-11-28 07:01:26

问题


I have an application that I'm trying to make multithreaded. Each thread will access a large chunk of read-only data.

Is is okay if multiple threads access the data simultaneously? I know that if the data were not read-only, I would need to use mutexes or some other form of synchronization to prevent race-conditions. But I'm wondering if it's okay to read the data without regard to synchronization.

The data in question will not be modified for the duration of all threads. The application will be running on Linux and Windows and is written in C++ if that makes any difference.


回答1:


If the data is read-only for the lifetime of all the threads that read it, then yes, it's perfectly fine to read without synchronization.




回答2:


If the data is truly read-only for the duration of the multi-threaded access, then no synchronization is necessary.




回答3:


Yes, that's fine.

You shouldn't have any problem.




回答4:


If the data is fixed before any of the reading threads start, then yes, it's OK.



来源:https://stackoverflow.com/questions/5643060/is-it-wise-to-access-read-only-data-from-multiple-threads-simultaneously

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