C++ 使用boost::named_条件时出错

C++ 使用boost::named_条件时出错,c++,boost,C++,Boost,我无法编译这个简单的示例(在VS 2008上): #包括 #包括 #包括 int main(int argc,const char*argv) { boost::进程间::命名的_条件cond(boost::进程间::仅创建_,“somd.notify”); boost::mutex_mutex; while(true) { const boost::system_time timeout=boost::get_system_time()+boost::posix_time::毫秒(500);

我无法编译这个简单的示例(在VS 2008上):

#包括
#包括
#包括
int main(int argc,const char*argv)
{
boost::进程间::命名的_条件cond(boost::进程间::仅创建_,“somd.notify”);
boost::mutex_mutex;
while(true)
{
const boost::system_time timeout=boost::get_system_time()+boost::posix_time::毫秒(500);
boost::mutex::作用域的_锁锁(_互斥锁);
if(条件定时\等待(锁定、超时))
{
//做些有用的事
}
}
返回0;
}
我得到的编译错误是(boostv1.38.0):

1>…\boost/interprocess/sync/named_condition.hpp(326):错误C2273:“函数样式转换”:作为“->”运算符的右侧是非法的
1> ..\src\main.cpp(13):请参阅对正在编译的函数模板实例化“bool boost::进程间::named_condition::timed_wait(L&,const boost::posix_time::ptime&)”的引用
1> 与
1>        [
1> L=boost::mutex::作用域锁定
1>        ]

想法?

我猜您必须使用不同的互斥类型:例如boost::interprocess::interprocess\u互斥

最佳管理者


Torsten

使用boost::interprocess::named_mutex,它可以很好地编译。
#include <boost/interprocess/sync/named_condition.hpp>
#include <boost/thread/mutex.hpp>
#include <string>

int main(int argc, const char* argv)
{
    boost::interprocess::named_condition cond(boost::interprocess::create_only, "somd.notify");
    boost::mutex the_mutex;
    while (true)
    {
        const boost::system_time timeout = boost::get_system_time() + boost::posix_time::milliseconds(500);
        boost::mutex::scoped_lock lock(the_mutex);
        if (cond.timed_wait(lock, timeout))
        {
            // Do something useful
        }
    }

    return 0;
}
1>....\boost/interprocess/sync/named_condition.hpp(326) : error C2273: 'function-style cast' : illegal as right side of '->' operator
1>        ..\src\main.cpp(13) : see reference to function template instantiation 'bool boost::interprocess::named_condition::timed_wait<boost::mutex::scoped_lock>(L &,const boost::posix_time::ptime &)' being compiled
1>        with
1>        [
1>            L=boost::mutex::scoped_lock
1>        ]