我正在尝试在互斥锁上创建一个定时作用域锁。我认为遵循 boost 的 api 可能会有所帮助,但我很难找到一些示例代码作为使用它的引用。
scoped_lock(mutex_type & m, const boost::posix_time::ptime & abs_time);
我想做这样的事情,
scoped_lock<interprocess_mutex> lock (_mutex, ? /* lock for 200 ms max */ ) ;
我的问题是如何创建持续时间为 200 毫秒的 posix_time::ptime 对象。我试图创建 time_duration 对象,但他们没有直接接受它的构造函数。
boost::posix_time::time_duration td = boost::posix_time::milliseconds(200);
有人可以帮我理解它是如何工作的吗?
最佳答案
只需将持续时间添加到当前时间:
auto now = boost::posix_time::microsec_clock::universal_time();
关于c++ - 创建 scoped_lock 最多 200 毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16711089/