- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
就线程安全和未定义行为而言,在多个线程从一个不变的单一源读取的情况下,我应该关注什么?
我正在研究一个允许独立进程并行执行的信号处理模型,这些进程可能共享一个输入缓冲区,但是填充输入缓冲区的进程总是会在下一阶段可能的并行进程执行之前完成.
在这种情况下我需要担心线程安全问题吗?我能做些什么呢?
我想指出,如果可能的话,无锁解决方案是最好的
最佳答案
but the process that fills the input buffer will always be complete before the next stage of possibly parallel processes will execute
如果能保证这一点,那么从不同线程多次读取 const 对象就不会有问题。
我没有官方标准所以以下来自n4296 :
17.6.5.9 Data race avoidance
3 A C++ standard library function shall not directly or indirectly modify objects (1.10) accessible by threads other than the current thread unless the objects are accessed directly or indirectly via the function’s non-const arguments, including this.
4 [ Note: This means, for example, that implementations can’t use a static object for internal purposes without synchronization because it could cause a data race even in programs that do not explicitly share objects between threads. —end note ]
这是 Herb Sutter video我第一次了解到 C++11 标准中 const
的含义的地方。 (见7:00到10:30左右)
关于c++ - 线程安全 : Multiple threads reading from a single const source,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37463861/
我是一名优秀的程序员,十分优秀!