|
From: Konstantin S. <kon...@gm...> - 2008-03-13 14:42:39
|
I have various situations similar to this one (at least, similar to
the minimized test).
I fix it by annotating the source code by Helgrind's client requests.
CONDVAR_SIGNAL and CONVAR_WAIT.
These client request are available only in HGDEV branch so far.
I've verified that it helps your test:
***************
*** 4,7 ****
--- 4,8 ----
#include <unistd.h>
#include <stdlib.h>
+ #include "dynamic_annotations.h"
static pthread_t threads[2];
***************
*** 24,27 ****
--- 25,29 ----
pthread_mutex_unlock(&lock);
} while (!stop);
+ ANNOTATE_CONDVAR_WAIT(&a_stopped);
// A has stopped, and waits for B to broadcast. Hence, it's safe
// to touch data. Helgrind reports this as a data race.
***************
*** 39,42 ****
--- 41,45 ----
pthread_mutex_lock(&lock);
a_stopped = 1;
+ ANNOTATE_CONDVAR_SIGNAL(&a_stopped);
pthread_cond_wait(&cond, &lock);
// Cleanup.
***************
*** 59,62 ****
return 0;
}
% g++ -g -lpthread bug.c
% /home/kcc/valgrind/hgdev/Inst/bin/valgrind --tool=helgrind ./a.out
...
==17530== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 10 from 3)
% g++ -g -lpthread -DDYNAMIC_ANNOTATIONS=1 bug.c dynamic_annotations.cc
...
==17643== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 10 from 3)
dynamic_annotations.h is a wrapper around helgrind client requests.
YOu may use client requests directly.
The real program *may* require slightly different client request.
--kcc
On Thu, Mar 13, 2008 at 4:35 PM, Erik Sandberg <san...@vi...> wrote:
> Hi,
>
> I'm working with a large project, where Helgrind gives a couple of false
> positives. I've been communicating with Julian for a while, but thought
> it's better to talk to this list.
>
> In my program, each thread owns some data which it manipulates. When an
> asynchronous event (such as user input) happens, all threads halt as
> soon as they can, and when all threads have halted, one of them handles
> the event. The event is executed by a single thread, so it may safely
> manipulate data owned by any thread.
>
> Helgrind complains about a data race, since it doesn't understand that
> some threads are sleeping.
>
> The attached file is a minimized version of my problem. Helgrind gives
> the following output:
>
> ==2518== Helgrind, a thread error detector.
> ==2518== Copyright (C) 2007-2008, and GNU GPL'd, by OpenWorks LLP et al.
> ==2518== Using LibVEX rev exported, a library for dynamic binary
> translation.
> ==2518== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
> ==2518== Using valgrind-3.4.0.SVN, a dynamic binary instrumentation
> framework.
> ==2518== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
> ==2518== For more details, rerun with: -v
> ==2518==
> ==2518== Thread #2 was created
> ==2518== at 0x511C91E: clone (in /lib/libc-2.7.so)
> ==2518== by 0x4E2FA11: pthread_create@@GLIBC_2.2.5 (in
> /lib/libpthread-2.7.so)
> ==2518== by 0x4C26928: pthread_create@* (hg_intercepts.c:213)
> ==2518== by 0x4007AD: main (bug.c:52)
> ==2518==
> ==2518== Thread #3 was created
> ==2518== at 0x511C91E: clone (in /lib/libc-2.7.so)
> ==2518== by 0x4E2FA11: pthread_create@@GLIBC_2.2.5 (in
> /lib/libpthread-2.7.so)
> ==2518== by 0x4C26928: pthread_create@* (hg_intercepts.c:213)
> ==2518== by 0x4007C6: main (bug.c:53)
> ==2518==
> ==2518== T3: Possible data race during write of size 4 at 0x600D20
> ==2518== at 0x40071E: threadB (bug.c:28)
> ==2518== by 0x4C26A43: mythread_wrapper (hg_intercepts.c:193)
> ==2518== by 0x4E2F3F6: start_thread (in /lib/libpthread-2.7.so)
> ==2518== by 0x511C95C: clone (in /lib/libc-2.7.so)
> ==2518== old state: e000002000000000 W #SS=1 #LS=0 S2/T2
> ==2518== new state: c000001000000000 W #SS=2 #LS=0 S2/T2 S4/T3
> ==2518== Location 0x600d20 is 0 bytes inside local var "data"
> ==2518== declared at bug.c:9, in frame #0 of thread 3
> ==2518==
> ==2518== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 9 from 3)
>
>
> Greetings,
> Erik
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Valgrind-developers mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-developers
>
>
|