Bug 322621

Summary: False positives with pthread_barrier_wait / helgrind
Product: [Developer tools] valgrind Reporter: dwachs
Component: helgrindAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: 3.6.0   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 3.12.0
Sentry Crash Report:
Attachments: sample program

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