Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6787: boost::thread::sleep() hangs if system time is rolled back
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-12-14 18:23:06
#6787: boost::thread::sleep() hangs if system time is rolled back
-----------------------------------------------+----------------------
Reporter: Artem Gayardo-Matrosov <boost@â¦> | Owner: viboes
Type: Bugs | Status: reopened
Milestone: | Component: thread
Version: Boost 1.49.0 | Severity: Problem
Resolution: | Keywords:
-----------------------------------------------+----------------------
Comment (by viboes):
next follows the whole code
{{{
void BOOST_THREAD_DECL sleep_for(const timespec& ts)
{
boost::detail::thread_data_base* const
thread_info=boost::detail::get_current_thread_data();
if(thread_info)
{
unique_lock<mutex> lk(thread_info->sleep_mutex);
while( thread_info->sleep_condition.do_wait_for(lk,ts)) {}
}
else
{
if (boost::detail::timespec_ge(ts,
boost::detail::timespec_zero()))
{
# if defined(BOOST_HAS_PTHREAD_DELAY_NP)
# if defined(__IBMCPP__)
BOOST_VERIFY(!pthread_delay_np(const_cast<timespec*>(&ts)));
# else
BOOST_VERIFY(!pthread_delay_np(&ts));
# endif
# elif defined(BOOST_HAS_NANOSLEEP)
// nanosleep takes a timespec that is an offset, not
// an absolute time.
nanosleep(&ts, 0);
# else
mutex mx;
unique_lock<mutex> lock(mx);
condition_variable cond;
cond.do_wait_for(lock, ts);
# endif
}
}
}
}}}
sleep_for() is one of the predefined thread interruption points. It is not
possible to use nanosleep and make it an interruption point.
I would like to separate standard threads and interruptible threads, but
this is not yet there.
What can I can do is define two functions sleep_for and sleep_until on a
different namespace
{{{
namespace non_interruptible {
template <class Clock, class Duration>
void sleep_until(const chrono::time_point<Clock, Duration>& t);
template <class Rep, class Period>
void sleep_for(const chrono::duration<Rep, Period>& d);
}
}}}
What do you think?
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6787#comment:13> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC