Question

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?

Was it helpful?

Solution

Just add the duration to the current time:

auto now = boost::posix_time::microsec_clock::universal_time();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top