|
From: Umesh K. <ume...@gm...> - 2011-12-15 12:46:04
|
Hi All ,
I'm newbie to valgrind and was trying my hands on the tool "helgrind" with
below samples .
#include <pthread.h>
#include<stdio.h>
int food =0 ;
pthread_mutex_t foodlock;
int child_fn ( ) {
pthread_mutex_lock(&foodlock);
if (food>=0) {
food++;
}
pthread_mutex_unlock(&foodlock);
* return food; //Read without lock ...Which may return with
un-predictable value here ..*..
}
int main ( void ) {
pthread_t child;
pthread_create(&child, NULL, child_fn, NULL);
pthread_join(child, NULL);
return 0;
}
Did you guys find any datarace issue in the above code ,If so why is
valgrind with helgrind or drd tool unable to find the same ..please find
the below report from valgrind
Helgrind Output
[umesh@localhost datarace]$ valgrind --tool=drd ./sample1
==8783== drd, a thread error detector
==8783== Copyright (C) 2006-2009, and GNU GPL'd, by Bart Van Assche.
==8783== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
==8783== Command: ./sample1
==8783==
==8783==
==8783== For counts of detected and suppressed errors, rerun with: -v
==8783== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 5)
DRD Output
[umesh@localhost datarace]$ valgrind --tool=helgrind ./sample1
==8785== Helgrind, a thread error detector
==8785== Copyright (C) 2007-2009, and GNU GPL'd, by OpenWorks LLP et al.
==8785== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
==8785== Command: ./sample1
==8785==
==8785==
==8785== For counts of detected and suppressed errors, rerun with: -v
==8785== Use --history-level=approx or =none to gain increased speed, at
==8785== the cost of reduced accuracy of conflicting-access information
==8785== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
Any lights on the above issue is appreciated .
Thanks
~Umesh
|