[Bug libstdc++/57641] std::timed_mutex.try_lock_until() is broken
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jun 18 17:27:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57641
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Testcase using clock with an earlier epoch:
#include <chrono>
#include <thread>
#include <mutex>
#include <assert.h>
namespace C = std::chrono;
struct clock
{
typedef C::system_clock::rep rep;
typedef C::system_clock::period period;
typedef C::system_clock::duration duration;
typedef std::chrono::time_point<clock> time_point;
static constexpr bool is_steady = C::system_clock::is_steady;
static time_point now() {
return time_point(C::system_clock::now().time_since_epoch() +
C::seconds(10));
}
};
std::timed_mutex mx;
void f()
{
mx.try_lock_until(clock::now() + C::milliseconds(1));
}
int main()
{
std::lock_guard<std::timed_mutex> l(mx);
auto start = C::system_clock::now();
std::thread t(f);
t.join();
auto stop = C::system_clock::now();
assert( (stop - start) < C::seconds(9) );
}
More information about the Gcc-bugs
mailing list