我应该使用 Helgrind 还是 DRD 进行线程错误检测?
看起来 Valgrind 有两个工具可以进行线程错误检测:Helgrind 和 DRD。这些工具基本相似。
我的主要问题是:什么时候应该使用其中一个而不是另一个来检查我的多线程代码?
更广泛地说,为什么有两种工具?我认为它们并不完全多余。有哪些重要的区别?我通常应该计划通过这两种工具运行我的代码吗?
Looks like Valgrind has two tools that both do thread error detection: Helgrind and DRD. These tools are substantially similar.
My primary question is: when should I use one instead of the other to check my multi-threaded code?
More broadly, why are there two tools? I assume they aren't entirely redundant. What are the important differences? Should I generally plan on running my code through both tools?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然 Helgrind 可以检测锁定顺序违规,但对于大多数程序,DRD 需要更少的内存来执行其分析。此外,DRD 支持分离线程。还有更多细微的差异 - 如果您想了解更多信息,请比较各自的手册。另请参阅http://valgrind.org/docs/manual/hg-manual.html 和 http://valgrind.org/docs/manual/drd-manual.html< /a>.
While Helgrind can detect locking order violations, for most programs DRD needs less memory to perform its analysis. Also, DRD has support for detached threads. There are more subtle differences too - compare the respective manuals if you want to know more. See also http://valgrind.org/docs/manual/hg-manual.html and http://valgrind.org/docs/manual/drd-manual.html.
取决于您想要检查该代码的内容。
要检查数据争用,您可能需要使用 ThreadSanitizer。
与 DRD 及其他方案的比较。
Depends on what you want to check that code for.
To check for data races, you might want to use ThreadSanitizer.
Comparison with DRD and others.
如果您使用除互斥体之外的任何 POSIX 同步原语(例如,信号量、屏障、条件变量等),DRD 值得一试——它可以识别 Helgrind 无法检测到的一些微妙的误用。
然而,DRD 似乎比 Helgrind 更消耗资源(在我使用 3.14.0 的运行中,似乎有大量的 CPU 开销)。
If you're using any POSIX synchronization primitives besides mutexes (e.g., semaphores, barriers, condition variables, etc.), DRD is worth a run -- it can identify some subtle misuses that Helgrind doesn't detect.
However, DRD seems to be much more resource intensive than Helgrind (in my runs using 3.14.0 there seems to be a tremendous amount of CPU overhead).
另一点需要考虑:从 valgrind 3.6.0 版本开始,DRD 支持 pthread 自旋锁,但 helgrind 不支持。我还没有尝试过 3.7.0,但发行说明让我相信这并没有改变。
One other point to consider: as of valgrind version 3.6.0, DRD supports pthread spinlocks, but helgrind doesn't. I haven't tried 3.7.0, but the release notes lead me to believe that this hasn't changed.