質問

Linux、gcc 4.3で、boost :: thread実装とmutex /条件変数を使用してクラスをコンパイルすると、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のcondition.hppで発生します。

if (!lock)
    throw lock_error();

Boost 1.38.0を使用していますが、Windowsでは問題はありません。助けていただければ幸いです!

役に立ちましたか?

解決

bufferLockではなく、m_mutexで待機する必要があります:

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

条件<!> lt; <!> gt; :: wait()は、 ScopedLock をパラメーターとして、 Mutex

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top