문제

Linux, GCC 4.3, Boost :: 스레드 구현 및 뮤트 / 조건 변수로 클래스를 컴파일하는 경우 Posix 스레드 라이브러리와의 유형 충돌로 인해 다음과 같은 이상한 오류가 발생합니다.

*Compiling: filter.cpp
/usr/include/boost/thread/condition.hpp: In member function »void boost::condition::wait(L&) [with L = boost::mutex]«:
/host/.../filter.cpp:68:   instantiated from here
/usr/include/boost/thread/condition.hpp:90: Error: no match für »operator!« in »!lock«*
*/usr/include/boost/thread/condition.hpp:90: Notice: candidates are: operator!(bool) <built in>*
*/usr/include/boost/thread/mutex.hpp:66: Error: »pthread_mutex_t boost::mutex::m_mutex« is private
/usr/include/boost/thread/condition.hpp:93: Error: in this context*

코드는 다음과 같습니다.

void CFilter::process( CData **s )
{
    boost::mutex::scoped_lock bufferLock(m_mutex);
    while (!m_bStop)
        m_change.wait(bufferLock);                      //<- line 68

    // ... further processing
}

클래스 선언과 함께

#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>

class CFilter
{
    // ...
    boost::shared_ptr<boost::thread> m_thread;
    boost::mutex m_mutex;
    boost::condition m_change;
    // ...

    process( CData **s );
}

연산자 오류는 boost의 조건에서 발생합니다 .hpp, in

if (!lock)
    throw lock_error();

Boost 1.38.0을 사용하고 있습니다. Windows에서는 아무런 문제가 없습니다. 모든 도움이 감사합니다!

도움이 되었습니까?

해결책

당신은 기다려야합니다 bufferLock, 아니다 m_mutex:

while (!m_bStop)
    m_change.wait(bufferLock);

조건 <> :: 대기 () a ScopedLock 매개 변수로서 Mutex.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top