This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/58038] New: std::this_thread::sleep_until can cause inifinite sleep
- From: "mario dot bielert at tu-dresden dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 31 Jul 2013 13:27:46 +0000
- Subject: [Bug libstdc++/58038] New: std::this_thread::sleep_until can cause inifinite sleep
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58038
Bug ID: 58038
Summary: std::this_thread::sleep_until can cause inifinite
sleep
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: mario.bielert@tu-dresden.de
Created attachment 30576
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30576&action=edit
Small test case, build with g++ -std=c++0x
When using sleep_until() I get an bug with unsigned long scalar representations
of a duration. If this duratoiin is in past, then you get an overflow in the
length of the argument for sleep_for(). This causes an almost infinte sleep,
instead of a fast return.
I solved this with defining two seperate implementions for sleep_until using
enable_if.
#################################################
/// sleep_until for signed representations
template<typename _Clock, typename _Duration>
inline
typename std::enable_if<std::is_signed<typename _Duration::rep>::value,
void>::type
sleep_until(const chrono::time_point<_Clock, _Duration>& __atime)
{
sleep_for(__atime - _Clock::now());
}
/// sleep_until for unsigned representations
template<typename _Clock, typename _Duration>
inline
typename std::enable_if<std::is_unsigned<typename _Duration::rep>::value,
void>::type
sleep_until(const chrono::time_point<_Clock, _Duration>& __atime)
{
typename _Clock::time_point _now = _Clock::now();
// check if we should sleep till a time point in past
if(__atime > _now)
// if not, procede as usual
sleep_for(__atime - _now);
}
#################################################
Sorry for not providing a .patch file, as I'm hacked my local installed
headers.