2010-02-20 23 views
1

Je me demande ce que je fais mal ... avec un seul wait il compile et fonctionne, mais pas avec un timed_wait:état anonyme interprocessus Boost timed_wait pas compilable

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 est un boost::interprocess::interprocess_mutex et obj->condition est un boost::interprocess::interprocess_condition. Voici le g ++ journal d'erreur:

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) 

alors que cela est le prototype de la fonction de membre de classe de condition (boost/interprocessus/synchronisation/interprocess_condition.hpp):

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

(stimuler 1.40)

Répondre

4

Grâce à un bel utilisateur #boost IRC (mjcaisse), j'ai maintenant un indice: timed_wait a besoin d'un temps absolu.

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