2009-03-07 17 views
1

auf Linux, gcc 4.3, eine Klasse mit boost :: Thread-Implementierung Kompilieren und mutexes/Bedingungsvariablen ich folgende seltsame Fehler erhalten, offenbar wegen Konflikten mit der Posix-Thread-Bibliothek geben:Boost-Thread-Compiler-Fehler mit GCC

*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* 

der Code ist:

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

    // ... further processing 
} 

mit der Klassendeklaration

#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); 
} 

Der Bedienfehler findet in condition.hpp der Schub in

if (!lock) 
    throw lock_error(); 

Ich bin mit Boost-1.38.0, auf Windows Ich habe keine Probleme. Jede Hilfe wird geschätzt!

Antwort

3

müssen Sie warten auf der bufferLock, nicht m_mutex:

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

Condition<>::wait() nimmt ein ScopedLock als Parameter, kein Mutex.

+0

Das ist richtig, aber es löst nicht das Problem, bleibt der Compiler-Fehler –

+0

Oh, es löst das Problem, mein Fehler! Vielen Dank –