<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - invalid high_resolution_clock::now behavior"
href="http://llvm.org/bugs/show_bug.cgi?id=22193">22193</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>invalid high_resolution_clock::now behavior
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>FreeBSD
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>edouard@quasardb.net
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>See this test program:
#include <chrono>
#include <iostream>
int main(int argc, char ** argv)
{
// although system_clock should be less precise the returned values should
be pretty close
// on my machine I have
// 2689496100548 (this is in the 70', YEAH BABY YEAH)
// 1421001821241019
std::cout <<
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count()
<< std::endl;
std::cout <<
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count()
<< std::endl;
return 0;
}
Looking at the source code, the problem is obvious:
// from chrono.cpp
system_clock::time_point
system_clock::now() _NOEXCEPT
{
timeval tv;
gettimeofday(&tv, 0);
return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
}
time_t
system_clock::to_time_t(const time_point& t) _NOEXCEPT
{
// correct because gettimeofday is epoch based
return time_t(duration_cast<seconds>(t.time_since_epoch()).count());
}
steady_clock::time_point
steady_clock::now() _NOEXCEPT
{
// incorrect, CLOCK_MONOTONIC returns an arbitrary value when calling
time_since_epoch it will fail
struct timespec tp;
if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
__throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>