提升进程间匿名条件 timed_wait 不可编译
Posted
技术标签:
【中文标题】提升进程间匿名条件 timed_wait 不可编译【英文标题】:Boost interprocess anonymous condition timed_wait not compilable 【发布时间】:2010-02-20 23:53:38 【问题描述】:我想知道我做错了什么......只有一个 wait
它可以编译和运行,但不是 timed_wait
:
using boost::interprocess::scoped_lock;
using boost::interprocess::interprocess_mutex;
using boost::posix_time::milliseconds;
[...]
scoped_lock<interprocess_mutex> lock(obj->mutex);
while (...)
obj->condition.timed_wait(lock, milliseconds(100));
其中obj->mutex
是boost::interprocess::interprocess_mutex
,obj->condition
是boost::interprocess::interprocess_condition
。这是 g++ 错误日志:
code.cpp: In member function ‘[...]’:
code.cpp:42: error: no matching function for call to ‘boost::interprocess::interprocess_condition::timed_wait(boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex>&, boost::posix_time::milliseconds)
而这是条件类成员函数的原型(boost/interprocess/sync/interprocess_condition.hpp):
template <typename L, typename Pr>
bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time, Pr pred)
(提升 1.40)
【问题讨论】:
【参考方案1】:感谢#boost IRC 用户 (mjcaisse),我现在有了一个线索:timed_wait 需要一个绝对时间。
bool noTimeout = true;
boost::system_time timeout = boost::get_system_time() + milliseconds(10);
while (!noTimeout && [CONDITION NOT MET])
noTimeout = obj->condition.timed_wait(lock, timeout);
if (!noTimeout)
std::cout << "timeout!" << std::endl;
【讨论】:
以上是关于提升进程间匿名条件 timed_wait 不可编译的主要内容,如果未能解决你的问题,请参考以下文章