on linux, gcc 4.3, compiling a class with boost::thread implementation and mutexes / condition variables I get the following strange error, apparently due to type conflicts with the posix thread library:
在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*
The code is:
代码是:
void CFilter::process( CData **s )
{
boost::mutex::scoped_lock bufferLock(m_mutex);
while (!m_bStop)
m_change.wait(bufferLock); //<- line 68
// ... further processing
}
with the class declaration
与类声明
#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 );
}
The operator error takes place in boost's condition.hpp, in
操作符错误发生在boost的condition.hpp中
if (!lock)
throw lock_error();
I'm using Boost 1.38.0, on Windows I don't find any problems. Any help is appreciated!
我正在使用Boost 1.38.0,在Windows上我没有发现任何问题。任何帮助表示赞赏!
1 个解决方案
#1
You must wait on the bufferLock
, not m_mutex
:
你必须等待bufferLock,而不是m_mutex:
while (!m_bStop)
m_change.wait(bufferLock);
Condition<>::wait() takes a ScopedLock
as parameter, not a Mutex
.
条件<> :: wait()将ScopedLock作为参数,而不是Mutex。
#1
You must wait on the bufferLock
, not m_mutex
:
你必须等待bufferLock,而不是m_mutex:
while (!m_bStop)
m_change.wait(bufferLock);
Condition<>::wait() takes a ScopedLock
as parameter, not a Mutex
.
条件<> :: wait()将ScopedLock作为参数,而不是Mutex。