2014-12-18 3 views
4

valgrind/helgrind 보고서를 기반으로하는 몇 가지 경쟁 조건이있는 boost :: thread 응용 프로그램을 프로그래밍했습니다. 이 종족의 이유를 밝히고 싶습니다.boost :: thread 응용 프로그램, 이상한 데이터 경합보고

이 프로그램은 다음과 같습니다이 간단한 프로그램 Valgrind의/helgrind이보고 다음과 같은 오류의

#include <boost/thread.hpp> 

boost::mutex myMutex; 
boost::condition_variable myConditionalVariable; 
bool functionWasRun = false; 

void function() 
{ 
    { 
     boost::lock_guard<boost::mutex> lock(myMutex); 
     functionWasRun = true; 
    } 
    myConditionalVariable.notify_one(); 

    //doSomething1(); 
} 

int main() 
{ 
    boost::thread pThread(function); 

    //Wait for the thread to start 
    boost::unique_lock<boost::mutex> lock(myMutex); 
    while (!functionWasRun) 
     myConditionalVariable.wait(lock); 

    //doSomething2(); 

    pThread.join(); 
} 

:

==10840== Helgrind, a thread error detector 
==10840== Copyright (C) 2007-2013, and GNU GPL'd, by OpenWorks LLP et al. 
==10840== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info 
==10840== Command: ./boost_network_test 
==10840== 
==10840== ---Thread-Announcement------------------------------------------ 
==10840== 
==10840== Thread #1 is the program's root thread 
==10840== 
==10840== ---Thread-Announcement------------------------------------------ 
==10840== 
==10840== Thread #2 was created 
==10840== at 0x6570EBE: clone (clone.S:74) 
==10840== by 0x4E44199: do_clone.constprop.3 (createthread.c:75) 
==10840== by 0x4E458BA: [email protected]@GLIBC_2.2.5 (createthread.c:245) 
==10840== by 0x4C30C90: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) 
==10840== by 0x547B3B8: boost::thread::start_thread_noexcept() (in /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.54.0) 
==10840== by 0x53CFCC: boost::thread::start_thread() (thread.hpp:180) 
==10840== by 0x53D31B: boost::thread::thread<void (&)()>(void (&)()) (thread.hpp:267) 
==10840== by 0x53CA7B: main (main_test.cpp:20) 
==10840== 
==10840== ---------------------------------------------------------------- 
==10840== 
==10840== Possible data race during read of size 8 at 0x8A21E0 by thread #1 
==10840== Locks held: none 
==10840== at 0x432CEB: boost::mutex::lock() (mutex.hpp:113) 
==10840== by 0x43D197: boost::unique_lock<boost::mutex>::lock() (lock_types.hpp:346) 
==10840== by 0x43C1A0: boost::unique_lock<boost::mutex>::unique_lock(boost::mutex&) (lock_types.hpp:124) 
==10840== by 0x53CA9E: main (main_test.cpp:23) 
==10840== 
==10840== This conflicts with a previous write of size 8 by thread #2 
==10840== Locks held: none 
==10840== at 0x432CF6: boost::mutex::lock() (mutex.hpp:113) 
==10840== by 0x43BFE9: boost::lock_guard<boost::mutex>::lock_guard(boost::mutex&) (lock_guard.hpp:38) 
==10840== by 0x53C9DE: function() (main_test.cpp:10) 
==10840== by 0x53DAAA: boost::detail::thread_data<void (*)()>::run() (thread.hpp:117) 
==10840== by 0x547BA49: ??? (in /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.54.0) 
==10840== by 0x4C30E26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) 
==10840== by 0x4E45181: start_thread (pthread_create.c:312) 
==10840== by 0x6570EFC: clone (clone.S:111) 
==10840== 
==10840== ---------------------------------------------------------------- 
==10840== 
==10840== Possible data race during write of size 8 at 0x8A21E0 by thread #1 
==10840== Locks held: none 
==10840== at 0x432CF6: boost::mutex::lock() (mutex.hpp:113) 
==10840== by 0x43D197: boost::unique_lock<boost::mutex>::lock() (lock_types.hpp:346) 
==10840== by 0x43C1A0: boost::unique_lock<boost::mutex>::unique_lock(boost::mutex&) (lock_types.hpp:124) 
==10840== by 0x53CA9E: main (main_test.cpp:23) 
==10840== 
==10840== This conflicts with a previous write of size 8 by thread #2 
==10840== Locks held: none 
==10840== at 0x432CF6: boost::mutex::lock() (mutex.hpp:113) 
==10840== by 0x43BFE9: boost::lock_guard<boost::mutex>::lock_guard(boost::mutex&) (lock_guard.hpp:38) 
==10840== by 0x53C9DE: function() (main_test.cpp:10) 
==10840== by 0x53DAAA: boost::detail::thread_data<void (*)()>::run() (thread.hpp:117) 
==10840== by 0x547BA49: ??? (in /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.54.0) 
==10840== by 0x4C30E26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) 
==10840== by 0x4E45181: start_thread (pthread_create.c:312) 
==10840== by 0x6570EFC: clone (clone.S:111) 
==10840== 
==10840== 
==10840== For counts of detected and suppressed errors, rerun with: -v 
==10840== Use --history-level=approx or =none to gain increased speed, at 
==10840== the cost of reduced accuracy of conflicting-access information 
==10840== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 15 from 15) 

당신이 날 내가 해결할 수있는 방법을 식별하는 데 도움이 될하시기 바랍니다 이 프로그램?

이 프로그램은 우분투 14.04LTS, x86_64, gcc 버전에서 실행됩니다. 4.8.2, libboost v.1.54, valgrind 3.10.0. 내 원래 프로그램은 경쟁 조건 패턴을보기 위해 최소한으로 줄인 ActiveObject 클래스를 사용하는 복잡한 응용 프로그램입니다.

이 스레드는 Debug boost::thread application, high false positive rate과 유사하지만 조건부 변수/뮤텍스와 관련되어 있습니다.

+3

그것은 나에게 helgrind 버그처럼 보이는,하지만 난 GCC 4.8.3로 재현, Valgrind의 3.9.0 및 1.54을 향상 할 수 없습니다

기억하려고하세요. 0 on Fedora 20 –

답변

-2

myConditionalVariable의 경쟁 조건 일 수 있습니까?

경우에 따라 아래에서 문제가 해결됩니다.

void function() 
{ 
    { 
     boost::lock_guard<boost::mutex> lock(myMutex); 
     functionWasRun = true; 
     myConditionalVariable.notify_one(); 
    } 

    //doSomething1(); 
} 

int main() 
{ 
    boost::thread pThread(function); 

    //Wait for the thread to start 
    while (!functionWasRun) 
    { 
     boost::unique_lock<boost::mutex> lock(myMutex); 
     myConditionalVariable.wait(lock); 
    } 

    //doSomething2(); 

    pThread.join(); 
} 
+0

잠금을 유지하는 동안 조건 변수를 알리는 것이 논리 오류입니다. –

+0

죄송합니다. 도움이되지 않았습니다. 이제 helgrind와 다른 불만이 있습니다. 스레드 1에서 크기 1을 읽는 동안 가능한 데이터 경쟁. 잠긴 상태 : 없음 (at : ... : main_test.cpp : 23), 이것은 이전 쓰기와 충돌합니다. 스레드 2에 의해 크기 1 잠금 : 1, 주소에서 ... at ... : function() (main_test.cpp : 11) – radekg1000

+0

예제는 boost 라이브러리 문서 http : //www.boost의 예제를 따릅니다. 조건부 변수 (동일한 mutex, 잠금 및 조건 변수 유형) 사용 방법에 대한 자세한 내용은 org/doc/libs/1_54_0/doc/html/thread/synchronization.html # thread.synchronization.condvar_ref를 참조하십시오. – radekg1000

3

좋은 소식은 프로그램이 올바른 것입니다. valgrind에 의해보고 된 모든 종족은 거짓 긍정입니다 (스레드에 참여하기 전에 뮤텍스를 잠금 해제하는 것을 고려해도 나중에 두통을 줄일 수 있습니다).

나는 이것을 시험해보기 위해 OSX10.10을 가지고 있기 때문에 최신 트렁크에서 valgrind를 빌드해야했다.

은 여기 (아래립니다 출력)

내가 : 표준 : : 스레드/표준으로 프로그램을 다시 썼다 뮤텍스 등 유사한 결과가 있었다을 내게 준거야.

잘린 출력 (즉 오류를보고하지 않음)

==79537== Helgrind, a thread error detector 
==79537== Copyright (C) 2007-2013, and GNU GPL'd, by OpenWorks LLP et al. 
==79537== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info 
==79537== Command: Build/Products/Debug/cpprules 
==79537== 
--79537-- Build/Products/Debug/cpprules: 
--79537-- dSYM directory is missing; consider using --dsymutil=yes 
--79537-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option 
--79537-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 2 times) 
--79537-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 4 times) 
==79537== ---Thread-Announcement------------------------------------------ 
==79537== 
==79537== Thread #2 was created 
==79537== at 0x10048D7EE: __bsdthread_create (in /usr/lib/system/libsystem_kernel.dylib) 
==79537== by 0x10003FC75: boost::thread::start_thread_noexcept() (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10000134E: main (in Build/Products/Debug/cpprules) 
==79537== 
==79537== ---Thread-Announcement------------------------------------------ 
==79537== 
==79537== Thread #1 is the program's root thread 
==79537== 
==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during read of size 4 at 0x1005AA2D8 by thread #2 
==79537== Locks held: none 
==79537== at 0x10058FFCF: spin_lock (in /usr/lib/system/libsystem_platform.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== 
==79537== This conflicts with a previous write of size 4 by thread #1 
==79537== Locks held: none 
==79537== at 0x10058FFDF: spin_unlock (in /usr/lib/system/libsystem_platform.dylib) 
==79537== by 0x10003FC75: boost::thread::start_thread_noexcept() (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10000134E: main (in Build/Products/Debug/cpprules) 
==79537== Address 0x1005aa2d8 is in the Data segment of /usr/lib/system/libsystem_pthread.dylib 
==79537== 
==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during read of size 4 at 0x103DEB010 by thread #2 
==79537== Locks held: none 
==79537== at 0x1005A3293: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== 
==79537== This conflicts with a previous write of size 4 by thread #1 
==79537== Locks held: none 
==79537== at 0x1005A30D8: pthread_create (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x10003FC75: boost::thread::start_thread_noexcept() (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10000134E: main (in Build/Products/Debug/cpprules) 
==79537== Address 0x103deb010 is in a rw- mapped file segment 
==79537== 
==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during write of size 4 at 0x103DEB010 by thread #2 
==79537== Locks held: none 
==79537== at 0x1005A329B: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== 
==79537== This conflicts with a previous write of size 4 by thread #1 
==79537== Locks held: none 
==79537== at 0x1005A30D8: pthread_create (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x10003FC75: boost::thread::start_thread_noexcept() (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10000134E: main (in Build/Products/Debug/cpprules) 
==79537== Address 0x103deb010 is in a rw- mapped file segment 
==79537== 
==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during write of size 4 at 0x1005AA2D8 by thread #2 
==79537== Locks held: none 
==79537== at 0x10058FFDF: spin_unlock (in /usr/lib/system/libsystem_platform.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== 
==79537== This conflicts with a previous write of size 4 by thread #1 
==79537== Locks held: none 
==79537== at 0x10058FFDF: spin_unlock (in /usr/lib/system/libsystem_platform.dylib) 
==79537== by 0x10003FC75: boost::thread::start_thread_noexcept() (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10000134E: main (in Build/Products/Debug/cpprules) 
==79537== Address 0x1005aa2d8 is in the Data segment of /usr/lib/system/libsystem_pthread.dylib 
==79537== 
==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during read of size 4 at 0x10004D118 by thread #2 
==79537== Locks held: none 
==79537== at 0x100048451: boost::thread_detail::enter_once_region(boost::once_flag&) (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10003FA54: boost::detail::set_current_thread_data(boost::detail::thread_data_base*) (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10003FD6C: boost::(anonymous namespace)::thread_proxy(void*) (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x1005A32FB: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== 
==79537== This conflicts with a previous write of size 4 by thread #1 
==79537== Locks held: none 
==79537== at 0x10004854A: boost::thread_detail::commit_once_region(boost::once_flag&) (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10003F9F4: boost::detail::get_current_thread_data() (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10000139F: main (in Build/Products/Debug/cpprules) 
==79537== Address 0x10004d118 is in the Data segment of /usr/local/lib/libboost_thread.dylib 
==79537== 
==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during read of size 8 at 0x10004D120 by thread #2 
==79537== Locks held: none 
==79537== at 0x10003FA78: boost::detail::set_current_thread_data(boost::detail::thread_data_base*) (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10003FD6C: boost::(anonymous namespace)::thread_proxy(void*) (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x1005A32FB: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== 
==79537== This conflicts with a previous write of size 8 by thread #1 
==79537== Locks held: none 
==79537== at 0x1005A1618: pthread_key_create (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x10003F9E8: boost::detail::get_current_thread_data() (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10000139F: main (in Build/Products/Debug/cpprules) 
==79537== Address 0x10004d120 is in the Data segment of /usr/local/lib/libboost_thread.dylib 
==79537== 
==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during read of size 8 at 0x1005AC448 by thread #2 
==79537== Locks held: none 
==79537== at 0x1005A269E: pthread_setspecific (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A32FB: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== 
==79537== This conflicts with a previous write of size 8 by thread #1 
==79537== Locks held: none 
==79537== at 0x1005A1614: pthread_key_create (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x10003F9E8: boost::detail::get_current_thread_data() (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10000139F: main (in Build/Products/Debug/cpprules) 
==79537== Address 0x1005ac448 is in the Data segment of /usr/lib/system/libsystem_pthread.dylib 
==79537== 
==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during write of size 1 at 0x100009D48 by thread #2 
==79537== Locks held: none 
==79537== at 0x100000F49: function() (in Build/Products/Debug/cpprules) 
==79537== by 0x10003FD79: boost::(anonymous namespace)::thread_proxy(void*) (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x1005A32FB: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== 
==79537== This conflicts with a previous read of size 1 by thread #1 
==79537== Locks held: none 
==79537== at 0x10000138D: main (in Build/Products/Debug/cpprules) 
==79537== Address 0x100009d48 is in the Data segment of Build/Products/Debug/cpprules 
==79537== 
==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during write of size 8 at 0x100009D28 by thread #2 
==79537== Locks held: none 
==79537== at 0x1005A4099: _pthread_cond_updateval (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A294D: _pthread_cond_signal (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x100000F77: function() (in Build/Products/Debug/cpprules) 
==79537== by 0x10003FD79: boost::(anonymous namespace)::thread_proxy(void*) (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x1005A32FB: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== 
==79537== This conflicts with a previous write of size 8 by thread #1 
==79537== Locks held: none 
==79537== at 0x1005A3DE1: _pthread_cond_wait (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1000014AA: main (in Build/Products/Debug/cpprules) 
==79537== Address 0x100009d28 is in the Data segment of Build/Products/Debug/cpprules 
==79537== 
==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during read of size 8 at 0x1005AC448 by thread #2 
==79537== Locks held: none 
==79537== at 0x1005A4791: _pthread_tsd_cleanup (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A44E4: _pthread_exit (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A3306: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== 
==79537== This conflicts with a previous write of size 8 by thread #1 
==79537== Locks held: none 
==79537== at 0x1005A1614: pthread_key_create (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x10003F9E8: boost::detail::get_current_thread_data() (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x10000139F: main (in Build/Products/Debug/cpprules) 
==79537== Address 0x1005ac448 is in the Data segment of /usr/lib/system/libsystem_pthread.dylib 
==79537== 

...

==79537== ---------------------------------------------------------------- 
==79537== 
==79537== Possible data race during write of size 8 at 0x100009C98 by thread #1 
==79537== Locks held: none 
==79537== at 0x1005A37DD: pthread_mutex_destroy (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x100005D50: boost::mutex::~mutex() (in Build/Products/Debug/cpprules) 
==79537== by 0x1003A38EC: __cxa_finalize_ranges (in /usr/lib/system/libsystem_c.dylib) 
==79537== by 0x1003A3BEF: exit (in /usr/lib/system/libsystem_c.dylib) 
==79537== by 0x1002F05CF: start (in /usr/lib/system/libdyld.dylib) 
==79537== 
==79537== This conflicts with a previous read of size 8 by thread #2 
==79537== Locks held: none 
==79537== at 0x1005A1655: _pthread_mutex_lock (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x100000EBB: function() (in Build/Products/Debug/cpprules) 
==79537== by 0x10003FD79: boost::(anonymous namespace)::thread_proxy(void*) (in /usr/local/lib/libboost_thread.dylib) 
==79537== by 0x1005A32FB: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A3278: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== by 0x1005A14B0: thread_start (in /usr/lib/system/libsystem_pthread.dylib) 
==79537== Address 0x100009c98 is in the Data segment of Build/Products/Debug/cpprules 
==79537== 
==79537== 
==79537== For counts of detected and suppressed errors, rerun with: -v 
==79537== Use --history-level=approx or =none to gain increased speed, at 
==79537== the cost of reduced accuracy of conflicting-access information 
==79537== ERROR SUMMARY: 34 errors from 33 contexts (suppressed: 0 from 0) 
+0

출력 결과는 문제가 단지 내 PC에만 국한되지 않고 재현 가능함을 보여줍니다. 위의 게시물에서와 같이 코드를 POSIX 스레드로 변환했습니다. 제 번역본이 Mac OS에서 컴파일되고 오류가 발생하지 않는지 확인할 수 있습니까? – radekg1000

+0

내가 집에 올 때 할 것이다 –

+0

Richard, 도와 줘서 고마워. 위의 최종 답을 달았습니다 (fprofile-arc 일). 문제가 귀하의 경우에보고되도록 내가 사용했던 깃발이 어디에 있는지 궁금합니다. – radekg1000

1

나는 POSIX 스레드 내 프로그램을 번역하고 지금 Helgrind 절대적으로 행복하다. 이 번역 후 내 프로그램입니다 :

#include <pthread.h> 
#include <stdio.h> 
#include <stdlib.h> 

::pthread_mutex_t myMutex; 
::pthread_cond_t myConditionVariable; 
bool functionWasRun = false; 

void* function(void*) 
{ 
    ::pthread_mutex_lock(&myMutex); 
    functionWasRun = true; 
    ::pthread_cond_signal(&myConditionVariable); 
    ::pthread_mutex_unlock(&myMutex); 

    //doSomething1(); 

    ::pthread_exit(NULL); 
} 

int main() 
{ 
    ::pthread_t thread; 
    int result; 

    ::pthread_mutex_init(&myMutex, NULL); 
    ::pthread_cond_init (&myConditionVariable, NULL); 

    result = ::pthread_create(&thread, NULL, function, 0); 
    if (result) 
    { 
     exit(-1); 
    } 

    //Wait for the thread to start 
    ::pthread_mutex_lock(&myMutex); 
    while (!functionWasRun) 
    { 
     ::pthread_cond_wait(&myConditionVariable, &myMutex); 
    } 
    ::pthread_mutex_unlock(&myMutex); 

    //doSomething2(); 

    result = ::pthread_join(thread, 0); 
    if (result) 
    { 
     exit(-1); 
    } 

    ::pthread_mutex_destroy(&myMutex); 
    ::pthread_cond_destroy(&myConditionVariable); 

    //Indicate that the program has been completed without errors 
    printf("Job done!\n"); 
} 

내 질문은 : 부스트 라이브러리를 사용하여 내가 POSIX 스레드에서 탈출하고 (적어도 윈도우) 이식을 원했다. 그러한 최소한의 프로그램에 대해 오탐 (false positive)을 제거하기 위해 어떻게해야할까요? 부스트가 내 뮤텍스 객체를 뮤텍스가 아닌 뮤텍스 기능을 가진 객체로 취급하고 전체 객체에 경주 탐지 정책을 적용하는 것을보기 시작합니다. 어떤 제안을 해주시겠습니까?

1

누군가가 장면 뒤에서 이상한 일이 발생했다고 말하면서 나는 그 이유를 발견했습니다.

부스트와 POSIX 변형 모두에서 코드에 이상한 것은 없습니다.요점은 코드가 코드 범위 (lcov)에 사용하는 -fprofile-arcs 플래그로 테스트 프레임 워크에서 컴파일되었다는 것입니다. 이 플래그는 프로그램을 계측하고 프로그램의 동작을 변경합니다. 내 경우에는 프로그램에 나타나는 모든 객체 (예 : boost :: mutex)가 계측되고 helgrind 출력을 방해합니다. 프로그램이 POSIX 쓰레드로 변환되었을 때, 모든 객체는 사라졌다. 그래서 역시 POSIX 변형이 왜 작동 하는지를 설명 할 것이다. HELGRIND = NO -fprofile-호에 FLAG