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

--- Comment #2 from John Salmon <john.salmon at deshaw dot com> ---
The same incorrect logic that was fixed in bug 68519 is present in the
implementations of future::wait_for and shared_timed_mutex::wait_for.  The fix
should be the same:  explicitly duration_cast the __rtime argument to
__clock::duration before adding to __clock::now().  Fixes are required in
shared_mutex and bits/atomic_futex.h.

The attached code demonstrates the problem.  wait_for either waits too long or
too short.  Output is:

drdws0134$ garden with -m gcc/8.1.0-01c7/bin g++ -std=c++14 futurewait.cpp
-pthread && ./a.out
ERROR - future::wait_for took too short: t1 looping: 0 milliseconds
0 second
t2 looping: 0 second
ERROR - shared_timed_mutex::try_lock_shared took too short: 0 milliseconds
t2 looping: 1 second
t1 looping: 1 second
t2 looping: 2 second
t1 looping: 2 second
t2 looping: 3 second
t1 looping: 3 second
t2 looping: 4 second
t1 looping: 4 second

Reply via email to