2010-02-20 51 views
1

我不知道我做錯了什麼?用它編譯唯一wait和運行,但不與timed_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_mutexobj->conditionboost::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) 

而這是條件類的成員函數的原型(升壓/間/同步/ interprocess_condition.hpp):

template <typename L, typename Pr> 
    bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time, Pr pred) 

(升壓1.40)

回答

4

感謝一位不錯的#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; 
}