当几个线程 *同时读取 *相同的内存时,是数据竞赛吗?
cppreference.com 说:
数据竞赛
评估表达式将修改为存储位置,并且 另一个评估读取或修改相同的内存位置, 表情被认为是冲突。一个有两个冲突的程序 评估有数据竞赛,除非...
这说明“ Thread1-Modify thread2-Read-Read”(MR)的场景以及“ Thread1-Modify thread2-Modify”(MM)的方案。
那'thread1-read thread2-read'(RR)呢?
cppreference.com says:
Data races
When an evaluation of an expression modifies to a memory location and
another evaluation reads or modifies the same memory location, the
expressions are said to conflict. A program that has two conflicting
evaluations has a data race unless...
This speaks about the scenario of 'thread1-modify thread2-read' (M-R) and about the scenario of 'thread1-modify thread2-modify' (M-M).
What about 'thread1-read thread2-read' (R-R)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
否。只要没有线程在该内存位置上没有编写未序列的线程,请读取内存测序不是数据竞赛。
这种情况可能不在对数据竞赛的描述中,因为这种情况不是数据竞赛。
No. Multiple threads reading memory sequenced is not a data race as long as no thread is writing unsequenced in that memory location.
That scenario was probably left out of that description of data races, because that scenario is not a data race.