1

Linux、gcc 4.3 で、boost::thread 実装とミューテックス / 条件変数を使用してクラスをコンパイルすると、明らかに 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 では問題はありません。どんな助けでも大歓迎です!

4

1 に答える 1