赫尔格林德和atomic_flag
Helgrind and atomic_flag
我在 cplusplus.com 尝试了使用atomic_flag
的基本示例。瓦尔格林德的赫尔格林德工具报告
164 errors from 28 contexts (suppressed: 0 from 0)
例如
==4868== Possible data race during read of size 1 at 0x605220 by thread #3
==4868== Locks held: none
==4868== at 0x401172: test_and_set (atomic_base.h:176)
==4868== by 0x401172: append_number(int) (helgrind_spinlock.cpp:12)
[output deleted]
==4868== This conflicts with a previous write of size 1 by thread #2
==4868== Locks held: none
==4868== at 0x4011C9: clear (atomic_base.h:193)
==4868== by 0x4011C9: append_number(int) (helgrind_spinlock.cpp:14)
[output deleted]
正确使用atomic_flag
作为旋转锁的参考是错误的,还是赫尔格林德在这里给出了误报?
这些是误报。赫尔格林德不理解"低级"同步, 它只理解 POSIX 同步原语。
请参阅用户手册 http://www.valgrind.org/docs/manual/hg-manual.html#hg-manual.effective-use,例如:
确保您的应用程序及其使用的所有库都使用 POSIX 线程原语。赫尔格林德需要能够看到所有内容 与线程创建、退出、锁定和其他相关的事件 同步事件。为此,它会拦截许多 POSIX pthread。 功能。
不要从中滚动自己的线程原语(互斥体等( Linux futex 系统调用、原子计数器等的组合。这些 将赫尔格林德的内部正在发生的事情模型抛出轨道, 会给出虚假的结果。
因此,等待 helgrind 理解例如 c++ 原子标志,您将拥有 使用客户端请求注释代码,让 Helgrind "看到"的 基于原子标志的同步基元。
相关文章:
- 如何从 std::atomic 中提取指针 T<T>?
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- std::memory_order for std::atomic:<T>:wait
- MESI协议和std::atomic-它是否确保所有写入立即对其他线程可见?
- 在 lambda 表达式中使用 std::atomic
- C++std::atomic在程序员级别保证了什么
- 如果在 2 个线程中使用,是否值得将size_t声明为 std::atomic?
- MyType 允许 std::atomic 的确切要求是什么<MyType>?
- 无法将类型"T&"的非常量左值引用绑定到类型"T"的右值 t++ std::atomic<T>
- gcc Atomic在gcc 4.1.1中内置了奇怪的行为
- 在 C++20 之前和之后初始化 std::atomic
- Red Hat:使用<atomic>编译很好,但链接器找不到__atomic_store_16;什么库?
- std::atomic 和 std::mutex 的相对性能
- 使用用户定义的类型 UDT 实例化 std::atomic<>。如果 UDT 具有虚函数,则 l 墨水将失败。为什么?
- 简单使用 std::atomic 在两个线程之间共享数据
- Port pthread_cond_broadcast to std::atomic
- std::atomic中的任何内容都是免费等待的
- 对于 CPU 无法原子操作的类型,std::atomic 有什么意义?
- 在 atomic() 中 ++、add operation 和 fetch_add() 有什么区别
- 最接近"std::atomic<std::vector>"是什么?