https://bugs.kde.org/show_bug.cgi?id=374414

            Bug ID: 374414
           Summary: unlocking mutex before calling notify_one/all on
                    condition variable triggers an error
           Product: valgrind
           Version: 3.10.0
          Platform: Debian stable
                OS: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: helgrind
          Assignee: jsew...@acm.org
          Reporter: yuva...@yahoo.com
  Target Milestone: ---

Created attachment 103121
  --> https://bugs.kde.org/attachment.cgi?id=103121&action=edit
file causing the error

When compiling the example from here (also attached file):
http://en.cppreference.com/w/cpp/thread/condition_variable
for using a C++11 std::condition_variable.
compilation:
 g++ -Wall -std=c++11 -g -O0 -Wall -o condition_variable condition_variable.cpp
-lpthread

It is specifically recommended to unlock the mutex before notification.
However, helgrind reports an error. If code is modified to send notification
when mutex is locked, the error disappears.

$ valgrind --tool=helgrind ./condition_variable
==11932== Helgrind, a thread error detector
==11932== Copyright (C) 2007-2013, and GNU GPL'd, by OpenWorks LLP et al.
==11932== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==11932== Command: ./condition_variable
==11932==
main() signals data ready for processing
==11932== ---Thread-Announcement------------------------------------------
==11932==
==11932== Thread #1 is the program's root thread
==11932==
==11932== ----------------------------------------------------------------
==11932==
==11932== Thread #1: pthread_cond_{signal,broadcast}: dubious: associated lock
is not held by any thread
==11932==    at 0x4C2D195: ??? (in
/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==11932==    by 0x510AC98: std::condition_variable::notify_one() (in
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11932==    by 0x401562: main (condition_variable.cpp:44)
==11932==
Worker thread is processing data
Worker thread signals data processing completed
==11932== ---Thread-Announcement------------------------------------------
==11932==
==11932== Thread #2 was created
==11932==    at 0x59625EE: clone (clone.S:74)
==11932==    by 0x4E422B9: do_clone.constprop.3 (createthread.c:75)
==11932==    by 0x4E43762: create_thread (createthread.c:245)
==11932==    by 0x4E43762: pthread_create@@GLIBC_2.2.5 (pthread_create.c:606)
==11932==    by 0x4C2EEBD: ??? (in
/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==11932==    by 0x510EA90:
std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>) (in
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11932==    by 0x401AFC: std::thread::thread<void (&)()>(void (&)())
(thread:138)
==11932==    by 0x401516: main (condition_variable.cpp:35)
==11932==
==11932== ----------------------------------------------------------------
==11932==
==11932== Thread #2: pthread_cond_{signal,broadcast}: dubious: associated lock
is not held by any thread
==11932==    at 0x4C2D195: ??? (in
/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==11932==    by 0x510AC98: std::condition_variable::notify_one() (in
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11932==    by 0x4014BC: worker_thread() (condition_variable.cpp:30)
==11932==    by 0x402C22: void std::_Bind_simple<void
(*())()>::_M_invoke<>(std::_Index_tuple<>) (functional:1700)
==11932==    by 0x402B6A: std::_Bind_simple<void (*())()>::operator()()
(functional:1688)
==11932==    by 0x402AE7: std::thread::_Impl<std::_Bind_simple<void (*())()>
>::_M_run() (thread:115)
==11932==    by 0x510E96F: ??? (in
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)
==11932==    by 0x4C2F056: ??? (in
/usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so)
==11932==    by 0x4E430A3: start_thread (pthread_create.c:309)
==11932==    by 0x596262C: clone (clone.S:111)
==11932==
Back in main(), data = Example data after processing
==11932==
==11932== For counts of detected and suppressed errors, rerun with: -v
==11932== Use --history-level=approx or =none to gain increased speed, at
==11932== the cost of reduced accuracy of conflicting-access information
==11932== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 33 from 33)

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to