0

I am trying to create a timed scoped lock on mutex. I thought following api from boost could help but I am having hard time finding some sample code as reference to use it.

scoped_lock(mutex_type & m, const boost::posix_time::ptime & abs_time);

I want to do it something like this,

scoped_lock<interprocess_mutex> lock (_mutex,  ? /* lock for 200 ms max */ ) ;

My question is how to create a posix_time::ptime object of duration 200ms. I tried to create time_duration object but their is no constructor that accepts it straight forward way.

boost::posix_time::time_duration td = boost::posix_time::milliseconds(200);

Can someone help me understand how it works please?

4

1 回答 1

2

只需将持续时间添加到当前时间:

auto now = boost::posix_time::microsec_clock::universal_time();
于 2013-05-23T10:12:08.830 回答