繁体   English   中英

Helgrind和atomic_flag

[英]Helgrind and atomic_flag

我尝试了在cplusplus.com上使用atomic_flag的基本示例。 Valgrind的Helgrind工具报告

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作为自旋锁的错误引用,或者Helgrind在这里给出了误报?

这些都是误报。 Helgrind不理解'低级'同步,它只理解posix同步原语。

参见用户手册http://www.valgrind.org/docs/manual/hg-manual.html#hg-manual.effective-use ,例如:

确保您的应用程序及其使用的所有库都使用POSIX线程原语。 Helgrind需要能够查看与线程创建,退出,锁定和其他同步事件有关的所有事件。 为此,它拦截了许多POSIX pthreads函数。

不要从Linux futex系统调用,原子计数器等的组合中滚动自己的线程原语(互斥体等)。这些使得Helgrind的内部正在进行的模型偏离正轨并且会给出虚假结果。

因此,等待helgrind理解例如c ++原子标志,你将不得不用客户端请求来注释代码,让helgrind“看到”基于原子标志的同步原语。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM