Valgrind – Helgrind – concurrency issue detection.
# Helgrind http://valgrind.org/docs/manual/hg-manual.html --tool=helgrind [root@localhost valgrindTest]# cat simpleDataRace.c /* Code from Valgrind Manual */ #include <pthread.h> int var = 0; void* child_fn ( void* arg ) { var++; /* Unprotected relative to parent */ /* this is line 6 */ return NULL; } int main ( void ) { pthread_t child; pthread_create(&child, NULL, child_fn, NULL); var++; /* Unprotected relative to child */ /* this is line 13 */ pthread_join(child, NULL); return 0; } [root@localhost valgrindTest]# gcc -Wall -g -lpthread -o simpleDataRace simpleDataRace.c [root@localhost valgrindTest]# valgrind --tool=helgrind ./simpleDataRace ==5733== Helgrind, a thread error detector ==5733== Copyright (C) 2007-2011, and GNU GPL'd, by OpenWorks LLP et al. ==5733== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==5733== Command: ./simpleDataRace ==5733== ==5733== ---Thread-Announcement------------------------------------------ ==5733== ==5733== Thread #1 is the program's root thread ==5733== ==5733== ---Thread-Announcement------------------------------------------ ==5733== ==5733== Thread #2 was created ==5733== at 0x6D8098: clone (in /lib/libc-2.5.so) ==5733== by 0x400B468: pthread_create_WRK (hg_intercepts.c:255) ==5733== by 0x400B53D: pthread_create@* (hg_intercepts.c:286) ==5733== by 0x804849E: main (simpleDataRace.c:12) ==5733== ==5733== ---------------------------------------------------------------- ==5733== ==5733== Possible data race during read of size 4 at 0x8049724 by thread #1 ==5733== Locks held: none ==5733== at 0x804849F: main (simpleDataRace.c:13) ==5733== ==5733== This conflicts with a previous write of size 4 by thread #2 ==5733== Locks held: none ==5733== at 0x804845F: child_fn (simpleDataRace.c:6) ==5733== by 0x400B5B8: mythread_wrapper (hg_intercepts.c:219) ==5733== by 0x798831: start_thread (in /lib/libpthread-2.5.so) ==5733== by 0x6D80AD: clone (in /lib/libc-2.5.so) ==5733== ==5733== ---------------------------------------------------------------- ==5733== ==5733== Possible data race during write of size 4 at 0x8049724 by thread #1 ==5733== Locks held: none ==5733== at 0x80484A7: main (simpleDataRace.c:13) ==5733== ==5733== This conflicts with a previous write of size 4 by thread #2 ==5733== Locks held: none ==5733== at 0x804845F: child_fn (simpleDataRace.c:6) ==5733== by 0x400B5B8: mythread_wrapper (hg_intercepts.c:219) ==5733== by 0x798831: start_thread (in /lib/libpthread-2.5.so) ==5733== by 0x6D80AD: clone (in /lib/libc-2.5.so) ==5733== ==5733== ==5733== For counts of detected and suppressed errors, rerun with: -v ==5733== Use --history-level=approx or =none to gain increased speed, at ==5733== the cost of reduced accuracy of conflicting-access information ==5733== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) [root@localhost valgrindTest]#
Hello,I log on to your blog named “Valgrind – dynamic code analysis tool – part III – Helgrind | davejingtian.org” regularly.Your humoristic style is awesome, keep up the good work! And you can look our website about free proxy.