* [Bug libstdc++/60421] std::this_thread::sleep_for doesn't sleep for all arguments
2014-03-05 9:19 [Bug libstdc++/60421] New: std::this_thread::sleep_for doesn't sleep for all arguments jaak at ristioja dot ee
@ 2014-03-05 10:50 ` plasmahh at gmx dot net
2014-03-05 11:30 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: plasmahh at gmx dot net @ 2014-03-05 10:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60421
Dennis Lubert <plasmahh at gmx dot net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |plasmahh at gmx dot net
--- Comment #1 from Dennis Lubert <plasmahh at gmx dot net> ---
Note that for me to reproduce this, _GLIBCXX_USE_NANOSLEEP must be defined. In
that case it uses directly the nanosleep call, casting the uint64max value to
time_t which is signed (which is unfortunately not visible in strace), gets
negative and this is what the nonsleep manpage says for glibc:
EINVAL The value in the tv_nsec field was not in the range 0 to
999999999 or tv_sec was negative.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/60421] std::this_thread::sleep_for doesn't sleep for all arguments
2014-03-05 9:19 [Bug libstdc++/60421] New: std::this_thread::sleep_for doesn't sleep for all arguments jaak at ristioja dot ee
2014-03-05 10:50 ` [Bug libstdc++/60421] " plasmahh at gmx dot net
@ 2014-03-05 11:30 ` redi at gcc dot gnu.org
2014-09-19 10:30 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2014-03-05 11:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60421
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
should probably be fixed along with PR 58038
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/60421] std::this_thread::sleep_for doesn't sleep for all arguments
2014-03-05 9:19 [Bug libstdc++/60421] New: std::this_thread::sleep_for doesn't sleep for all arguments jaak at ristioja dot ee
2014-03-05 10:50 ` [Bug libstdc++/60421] " plasmahh at gmx dot net
2014-03-05 11:30 ` redi at gcc dot gnu.org
@ 2014-09-19 10:30 ` redi at gcc dot gnu.org
2015-03-26 20:08 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2014-09-19 10:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60421
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-09-19
Target Milestone|--- |5.0
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/60421] std::this_thread::sleep_for doesn't sleep for all arguments
2014-03-05 9:19 [Bug libstdc++/60421] New: std::this_thread::sleep_for doesn't sleep for all arguments jaak at ristioja dot ee
` (2 preceding siblings ...)
2014-09-19 10:30 ` redi at gcc dot gnu.org
@ 2015-03-26 20:08 ` redi at gcc dot gnu.org
2015-03-26 20:14 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2015-03-26 20:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60421
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Thu Mar 26 19:59:08 2015
New Revision: 221708
URL: https://gcc.gnu.org/viewcvs?rev=221708&root=gcc&view=rev
Log:
PR libstdc++/58038
PR libstdc++/60421
* include/std/thread (this_thread::sleep_for): Check for negative
durations.
(this_thread::sleep_until): Check for times in the past.
* testsuite/30_threads/this_thread/58038.cc: New.
* testsuite/30_threads/this_thread/60421.cc: New.
Added:
trunk/libstdc++-v3/testsuite/30_threads/this_thread/58038.cc
trunk/libstdc++-v3/testsuite/30_threads/this_thread/60421.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/std/thread
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/60421] std::this_thread::sleep_for doesn't sleep for all arguments
2014-03-05 9:19 [Bug libstdc++/60421] New: std::this_thread::sleep_for doesn't sleep for all arguments jaak at ristioja dot ee
` (3 preceding siblings ...)
2015-03-26 20:08 ` redi at gcc dot gnu.org
@ 2015-03-26 20:14 ` redi at gcc dot gnu.org
2015-03-26 22:28 ` jaak at ristioja dot ee
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2015-03-26 20:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60421
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for gcc5.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/60421] std::this_thread::sleep_for doesn't sleep for all arguments
2014-03-05 9:19 [Bug libstdc++/60421] New: std::this_thread::sleep_for doesn't sleep for all arguments jaak at ristioja dot ee
` (4 preceding siblings ...)
2015-03-26 20:14 ` redi at gcc dot gnu.org
@ 2015-03-26 22:28 ` jaak at ristioja dot ee
2015-03-26 23:45 ` jaak at ristioja dot ee
2015-03-27 3:47 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jaak at ristioja dot ee @ 2015-03-26 22:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60421
--- Comment #5 from Jaak Ristioja <jaak at ristioja dot ee> ---
(In reply to Jonathan Wakely from comment #4)
> Fixed for gcc5.
Looking at the diff <thread> of revision 221708, I fail to see how the
if (__rtime <= __rtime.zero())
return;
check in sleep_for() prevents the EINVAL in nanosleep(3p), as is the original
issue.
I mean aren't we dealing here with unsigned (decltype(_rtime)) to signed
(std::time_t) conversion?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/60421] std::this_thread::sleep_for doesn't sleep for all arguments
2014-03-05 9:19 [Bug libstdc++/60421] New: std::this_thread::sleep_for doesn't sleep for all arguments jaak at ristioja dot ee
` (5 preceding siblings ...)
2015-03-26 22:28 ` jaak at ristioja dot ee
@ 2015-03-26 23:45 ` jaak at ristioja dot ee
2015-03-27 3:47 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jaak at ristioja dot ee @ 2015-03-26 23:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60421
Jaak Ristioja <jaak at ristioja dot ee> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|FIXED |---
--- Comment #6 from Jaak Ristioja <jaak at ristioja dot ee> ---
I mean when I sleep for UINT64_MAX hours/years/millenia, you can't possibly
wrap that into a single nanosleep call due to the limitations of the type
time_t of the tv_sec parameter of the first argument to nanosleep. One
obviously can not get around using loop.
Additionally, the nanosleep code is also missing proper EINTR handling, which
again could break the sleep.
Reopening.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/60421] std::this_thread::sleep_for doesn't sleep for all arguments
2014-03-05 9:19 [Bug libstdc++/60421] New: std::this_thread::sleep_for doesn't sleep for all arguments jaak at ristioja dot ee
` (6 preceding siblings ...)
2015-03-26 23:45 ` jaak at ristioja dot ee
@ 2015-03-27 3:47 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2015-03-27 3:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60421
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|5.0 |6.0
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
You're right, sorry, I ended up reducing the scope of the fix and it only deals
with PR58038, see https://gcc.gnu.org/ml/libstdc++/2015-03/msg00078.html for
some commentary.
At one point I added:
if (__s < chrono::seconds::zero() || __s < __rtime)
__s = chrono::seconds::max();
which would detect some cases where the duration_cast to chrono::seconds
overflows, but that overflow is still undefined behaviour so I didn't include
that in the commit. I want to fix it properly to avoid any undefined behaviour
(probably converting to duration<long double> and comparing to
duration<time_t>::max()).
> I mean when I sleep for UINT64_MAX hours/years/millenia, you can't possibly
> wrap that into a single nanosleep call due to the limitations of the type
> time_t of the tv_sec parameter of the first argument to nanosleep. One
> obviously can not get around using loop.
To be honest, I'm not very concerned about the failure to sleep for 290 billion
years, if we sleep for duration<time_t>::max() instead of
duration<uint64_t>::max() and don't loop you'll never know the difference.
> Additionally, the nanosleep code is also missing proper EINTR handling,
> which again could break the sleep.
Yes, see the mailing list post above.
I'll deal with this for gcc 6.
^ permalink raw reply [flat|nested] 9+ messages in thread