Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use Helgrind or DRD for thread error detection?

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?

like image 560
Jeff Terrell Ph.D. Avatar asked Nov 16 '11 19:11

Jeff Terrell Ph.D.


People also ask

Which of the following is are detected multithreading issues in Valgrind and DRD?

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.

What is DRD in Valgrind?

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.

What does Helgrind do?

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.

Is Valgrind single threaded?

Valgrind doesn't schedule the threads itself. It merely ensures that only one thread runs at once, using a simple locking scheme.


3 Answers

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.

like image 58
Bart Van Assche Avatar answered Sep 20 '22 05:09

Bart Van Assche


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.

like image 31
Employed Russian Avatar answered Sep 21 '22 05:09

Employed Russian


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).

like image 20
jhfrontz Avatar answered Sep 20 '22 05:09

jhfrontz