Discussion:
[Bug c++/58931] New: condition_variable::wait_until overflowed by large time_point<steady_clock>
lundberj at gmail dot com
2013-10-30 22:46:21 UTC
Permalink
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58931

Bug ID: 58931
Summary: condition_variable::wait_until overflowed by large
time_point<steady_clock>
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: lundberj at gmail dot com

With valid but large steady clock time_points, condition_variable.wait_until
does not sleep at all, but instead continues as if the time was passed.

Perhaps related to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54562

Example:

#include <chrono>
#include <mutex>
#include <condition_variable>
int main(){
std::mutex m;
std::condition_variable cv;
std::unique_lock<std::mutex> lk(m);
// does not sleep at all:
cv.wait_until(lk,
std::chrono::time_point<std::chrono::steady_clock>::max());
// sleeps fine:
//cv.wait_until(lk,
// std::chrono::steady_clock::now()+10000*std::chrono::hours{24*365});
}

cheers / Johan -thanks for a great compiler!

PS.
* I compiled gcc with --enable-libstdcxx-time=yes. Using 64 bit linux 3.5.0
* The bug does not occur with system_clock.
* I used time_point max() to let a worker thread wait when a queue of delayed
events was empty.
redi at gcc dot gnu.org
2013-10-31 13:29:30 UTC
Permalink
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58931

Jonathan Wakely <redi at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |redi at gcc dot gnu.org

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I have a fix for PR 54562 so I'll see if it solves this.

N.B. --enable-libstdcxx-time=yes should not be necessary for 4.8 if you have
glibc 2.17 or later.
redi at gcc dot gnu.org
2013-11-11 12:55:02 UTC
Permalink
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58931

Jonathan Wakely <redi at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-11-11
Component|c++ |libstdc++
Ever confirmed|0 |1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixing PR 54562 doesn't help. This can be reduced to

#include <chrono>
#include <cassert>

int main()
{
using StClock = std::chrono::steady_clock;
using SysClock = std::chrono::system_clock;
auto st_atime = std::chrono::time_point<StClock>::max();
const StClock::time_point st_now = StClock::now();
const SysClock::time_point sys_now = SysClock::now();
const auto delta = st_atime - st_now;
const auto sys_atime = sys_now + delta;
assert( sys_atime > sys_now );
}

Loading...