Helgrind: a thread error detector
4. Make sure you are using a supported Linux distribution.
At present, Helgrind only properly supports glibc-2.3
or later.
This in turn means we only support glibc’s NPTL threading implementation.
The old LinuxThreads
implementation is not supported.
5. Round up all finished threads using
pthread_join
.
Avoid detaching threads: don’t create threads in the
detached state, and don’t call
pthread_detach
on existing threads.
Using
pthread_join
to round up finished threads provides a clear synchronisation point that both Helgrind and
programmers can see.
If you don’t call
pthread_join
on a thread, Helgrind has no way to know when it
finishes, relative to any significant synchronisation points for other threads in the program. So it assumes that the
thread lingers indefinitely and can potentially interfere indefinitely with the memory state of the program. It has
every right to assume that -- after all, it might really be the case that, for scheduling reasons, the exiting thread did
run very slowly in the last stages of its life.
6. Perform thread debugging (with Helgrind) and memory debugging (with Memcheck) together.
Helgrind tracks the state of memory in detail, and memory management bugs in the application are liable to cause
confusion. In extreme cases, applications which do many invalid reads and writes (particularly to freed memory)
have been known to crash Helgrind. So, ideally, you should make your application Memcheck-clean before using
Helgrind.
It may be impossible to make your application Memcheck-clean unless you first remove threading bugs.
In
particular, it may be difficult to remove all reads and writes to freed memory in multithreaded C++ destructor
sequences at program termination. So, ideally, you should make your application Helgrind-clean before using
Memcheck.
Since this circularity is obviously unresolvable, at least bear in mind that Memcheck and Helgrind are to some
extent complementary, and you may need to use them together.
7. POSIX requires that implementations of standard I/O (
printf
,
fprintf
,
fwrite
,
fread
, etc) are thread safe.
Unfortunately GNU libc implements this by using internal locking primitives that Helgrind is unable to intercept.
Consequently Helgrind generates many false race reports when you use these functions.
Helgrind attempts to hide these errors using the standard Valgrind error-suppression mechanism. So, at least for
simple test cases, you don’t see any. Nevertheless, some may slip through. Just something to be aware of.
8. Helgrind’s error checks do not work properly inside the system threading library itself (
libpthread.so
), and it
usually observes large numbers of (false) errors in there. Valgrind’s suppression system then filters these out, so
you should not see them.
If you see any race errors reported where
libpthread.so
or
ld.so
is the object associated with the innermost
stack frame, please file a bug report at http://www.valgrind.org/.
7.6. Helgrind Command-line Options
The following end-user options are available:
--free-is-write=no|yes [default:
no]
When enabled (not the default), Helgrind treats freeing of heap memory as if the memory was written immediately
before the free. This exposes races where memory is referenced by one thread, and freed by another, but there is no
observable synchronisation event to ensure that the reference happens before the free.
This functionality is new in Valgrind 3.7.0, and is regarded as experimental. It is not enabled by default because its
interaction with custom memory allocators is not well understood at present. User feedback is welcomed.
118
Содержание BBV
Страница 176: ...Valgrind FAQ Release 3 8 0 10 August 2012 Copyright 2000 2012 Valgrind Developers Email valgrind valgrind org ...
Страница 177: ...Valgrind FAQ Table of Contents Valgrind Frequently Asked Questions 1 ii ...
Страница 302: ...README mips based on newer GCC versions if possible 95 ...
Страница 303: ...GNU Licenses ...
Страница 304: ...GNU Licenses Table of Contents 1 The GNU General Public License 1 2 The GNU Free Documentation License 8 ii ...