This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
clock() time travel.
- From: PaweÅ Sikora <pluto at agmk dot net>
- To: <libc-help at sourceware dot org>
- Date: Thu, 16 Jan 2014 11:54:09 +0100
- Subject: clock() time travel.
- Authentication-results: sourceware.org; auth=none
Hi,
i've observed on my i3-540 cpu that subsequent clock() calls
*sometimes* give smaller number of ticks than previous one.
is it a known issue?
BR,
PaweÅ.
% ./timing
t[current]: 10713902 < t[previous]: 10713903
zsh: abort (core dumped) ./timing
gcc-4.8.2-7.fc20.x86_64
glibc-2.18-11.fc20.x86_64
kernel-3.12.7-300.fc20.x86_64
% cat timing.c
#include <pthread.h>
#include <sched.h>
#include <stdio.h>
#include <time.h>
void* th0( void* args )
{
int N = 10000000, i;
for ( i = 0; i < N; i++ )
{
sched_yield();
}
return NULL;
}
void* th1( void* args )
{
int N = 10000000, i;
for ( i = 0; i < N; i++ )
{
clock_t t0 = clock();
sched_yield();
clock_t t1 = clock();
if ( t1 < t0 )
{
printf( "t[current]: %ld < t[previous]: %ld\n", t1, t0 );
__builtin_abort();
}
}
return NULL;
}
int main( int argc, char** argv )
{
pthread_t t0, t1;
pthread_create( &t0, NULL, th0, NULL );
pthread_create( &t1, NULL, th1, NULL );
pthread_join( t0, NULL );
pthread_join( t1, NULL );
return 0;
}