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?
Helgrind and DRD are both thread error detectors. This basically means that they will attempt to detect any multithreading issues such as data races and incorrect use of mutexes.
DRD is a Valgrind tool for detecting errors in multithreaded C and C++ programs. The tool works for any program that uses the POSIX threading primitives or that uses threading concepts built on top of the POSIX threading primitives.
Helgrind is a Valgrind tool for detecting synchronisation errors in C/C++ programs that use the POSIX threading primitives. The main abstractions in POSIX are: a set of threads sharing a common address space, thread creation, thread joining, thread exit, mutexes (locks), condition variables and barriers.
Valgrind doesn't schedule the threads itself. It merely ensures that only one thread runs at once, using a simple locking scheme.
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.
when should I use one instead of the other to check my multi-threaded code?
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With