I implemented a fast function which returns time (using rdtsc), let's call it fast_time()
. I have for reference the original function which uses a system call, let's call it system_time()
. My program uses fast_time()
but in a separate thread I'm constantly running a while loop to check if the difference between the time returned from the my function and the original function is greater than a predefined threshold. Something like
while (true)
{
if (abs((fast_time() - system_time()).microseconds()) > MICROSECONDS_THRESHOLD)
{
report error
}
}
Usually I don't see errors but sometimes I do get them and I would like to understand this problem better. My first suspicion is that the call to system_time()
doesn't happen immediately after fast_time()
returns. How can I force the program to execute fast_time() - system_time()
"atomically" as possible?