创建一个boost :: posix_time :: ptime实例,持续X个毫秒

Ode*_*ded 0 c++ linux boost

boost::interprocess::scoped_lock<boost::interprocess::named_recursive_mutex>
Run Code Online (Sandbox Code Playgroud)

在创建实例时,我需要使用

scoped_lock(mutex_type & m, const boost::posix_time::ptime & abs_time);
Run Code Online (Sandbox Code Playgroud)

构造函数.如何为X个毫秒创建一个scoped_lock?

Key*_*lug 5

如果X是您在等待锁定获取时要花费的毫秒数,那么此代码段应该可以帮助您:

boost::posix_time::ptime till = boost::posix_time::microsec_clock::local_time() + 
    boost::posix_time::milliseconds(X);
...
{
    boost::interprocess::scoped_lock(some_mutex, till);
    ...
}
Run Code Online (Sandbox Code Playgroud)