|
From: Bart V. A. <bva...@ac...> - 2011-12-16 11:28:06
|
On Thu, Dec 15, 2011 at 1:45 PM, Umesh Kalappa <ume...@gm...> wrote:
> 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 and DRD check for unordered accesses issued by different
threads. Your program does not trigger any such unordered accesses and
that is why neither Helgrind nor DRD complains.
There exists another class of data-race detection tools that reports
all accesses of shared variables that are not consistently protected
by locking. A disadvantage of these tools is that these can report a
large number of false positive reports.
More information can be found here:
http://valgrind.org/docs/manual/drd-manual.html#drd-manual.data-race-detection.
Bart.
|