public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58931] New: condition_variable::wait_until overflowed by large time_point<steady_clock>
@ 2013-10-30 22:46 lundberj at gmail dot com
  2013-10-31 13:29 ` [Bug c++/58931] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: lundberj at gmail dot com @ 2013-10-30 22:46 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/58931] condition_variable::wait_until overflowed by large time_point<steady_clock>
  2013-10-30 22:46 [Bug c++/58931] New: condition_variable::wait_until overflowed by large time_point<steady_clock> lundberj at gmail dot com
@ 2013-10-31 13:29 ` redi at gcc dot gnu.org
  2013-11-11 12:55 ` [Bug libstdc++/58931] " redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-10-31 13:29 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/58931] condition_variable::wait_until overflowed by large time_point<steady_clock>
  2013-10-30 22:46 [Bug c++/58931] New: condition_variable::wait_until overflowed by large time_point<steady_clock> lundberj at gmail dot com
  2013-10-31 13:29 ` [Bug c++/58931] " redi at gcc dot gnu.org
@ 2013-11-11 12:55 ` redi at gcc dot gnu.org
  2015-05-09 22:45 ` aaron at aarongraham dot com
  2020-10-03 17:55 ` mac at mcrowe dot com
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-11-11 12:55 UTC (permalink / raw)
  To: gcc-bugs

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 );
}


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/58931] condition_variable::wait_until overflowed by large time_point<steady_clock>
  2013-10-30 22:46 [Bug c++/58931] New: condition_variable::wait_until overflowed by large time_point<steady_clock> lundberj at gmail dot com
  2013-10-31 13:29 ` [Bug c++/58931] " redi at gcc dot gnu.org
  2013-11-11 12:55 ` [Bug libstdc++/58931] " redi at gcc dot gnu.org
@ 2015-05-09 22:45 ` aaron at aarongraham dot com
  2020-10-03 17:55 ` mac at mcrowe dot com
  3 siblings, 0 replies; 5+ messages in thread
From: aaron at aarongraham dot com @ 2015-05-09 22:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58931

--- Comment #4 from Aaron Graham <aaron at aarongraham dot com> ---
See bug 41861 for discussion of steady_clock wrt condition_variable.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/58931] condition_variable::wait_until overflowed by large time_point<steady_clock>
  2013-10-30 22:46 [Bug c++/58931] New: condition_variable::wait_until overflowed by large time_point<steady_clock> lundberj at gmail dot com
                   ` (2 preceding siblings ...)
  2015-05-09 22:45 ` aaron at aarongraham dot com
@ 2020-10-03 17:55 ` mac at mcrowe dot com
  3 siblings, 0 replies; 5+ messages in thread
From: mac at mcrowe dot com @ 2020-10-03 17:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58931

Mike Crowe <mac at mcrowe dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mac at mcrowe dot com

--- Comment #6 from Mike Crowe <mac at mcrowe dot com> ---
This problem isn't as serious now that waiting on std::chrono::steady_clock
doesn't use the generic wait_until implemenation, but it's worth fixing
regardless.

I have a reproduction case and Aaron's fix in attachment 43261 (with some minor
tweaks to accommodate the recent addition of __detail::ceil) still appears to
work.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-03 17:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-30 22:46 [Bug c++/58931] New: condition_variable::wait_until overflowed by large time_point<steady_clock> lundberj at gmail dot com
2013-10-31 13:29 ` [Bug c++/58931] " redi at gcc dot gnu.org
2013-11-11 12:55 ` [Bug libstdc++/58931] " redi at gcc dot gnu.org
2015-05-09 22:45 ` aaron at aarongraham dot com
2020-10-03 17:55 ` mac at mcrowe dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).