从多个线程同时访问只读数据是明智的吗? [英] Is it wise to access read-only data from multiple threads simultaneously?

查看:241
本文介绍了从多个线程同时访问只读数据是明智的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我试图做多线程。每个线程都将访问一个大块的只读数据。

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.

推荐答案

如果数据被读取,应用程序将在Linux和Windows上运行,并且用C ++编写。 - 只在读取它的所有线程的生命周期,然后是,它是完全没有同步读取。

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.

这篇关于从多个线程同时访问只读数据是明智的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆