Bug 322621 - False positives with pthread_barrier_wait / helgrind
Summary: False positives with pthread_barrier_wait / helgrind
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: helgrind (show other bugs)
Version: 3.6.0
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-20 14:49 UTC by dwachs
Modified: 2018-03-17 19:23 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 3.12.0
Sentry Crash Report:


Attachments
sample program (1.54 KB, text/x-c++src)
2013-07-20 14:49 UTC, dwachs
Details

Note You need to log in before you can comment on or make changes to this bug.
Description dwachs 2013-07-20 14:49:23 UTC
Created attachment 81219 [details]
sample program

In the program there are two threads synchronized by barriers. There are two buffers: one is filled by a thread, the other buffer is read by the main thread. Switching of buffers happens on the barrier. 

Helgrind reports errors for the reading thread, however the barrier is there to ensure that reading happens after writing. Imho these are false positives.

Compile and run the attached program:

g++   -lpthread  barrier.cc   -o barrier
valgrind --tool=helgrind ./barrier

Helgrind output:


==17634== Thread #1 is the program's root thread
==17634== 
==17634== Possible data race during read of size 1 at 0x5c55080 by thread #1
==17634==    at 0x4009F0: read_buffer(int) (in barrier)
==17634==    by 0x400B6D: main (in barrier)
==17634==  Address 0x5c55080 is 0 bytes inside a block of size 1048576 alloc'd
==17634==    at 0x4C28D47: operator new[](unsigned long) (in /usr/lib64/valgrind/vgpreload_helgrind-amd64-linux.so)
==17634==    by 0x400AB7: main (in barrier)
==17634== 

gcc version: 4.6.2
valgrind version: 3.6.1
Comment 1 dwachs 2013-07-20 14:56:59 UTC
Program flow is like:

 Create thread

 Main: nothing  ...  Thread: fill buffer 1
<-- barrier -->
Main: read buffer 1 ... Thread: Fill buffer 0
<-- barrier -->

etc
Comment 2 dwachs 2018-03-17 19:23:00 UTC
Appears to be fixed:

g++ 4.8.5
valgrind 3.12.0