I have checked that my system is supporting microsec precision how to make system support nanosec precision Using boost timer I am able to print the current time in microsec precision Print current time in microsec
Now when I check whether nanosleep / usleep is working or not, I run this program .
Here is my program1
Print current time in microsec
usleep(1); // sleep for 1 microsec
Print current time in microsec
Here is my output
01:43:38.799150
01:43:38.799393
When I run this program2
struct timespec delay;
delay.tv_sec = 0;
delay.tv_nsec = 1000;
Print current time in microsec
nanosleep(&delay, NULL);
Print current time in microsec
I got this output
01:48:25.919269
01:48:25.919838
I am expecting only 1 microsec difference in current time whereas actually I am getting more than 100 microsec difference. What's the reason?
I doubt whether my system properly execute usleep/nanosleep although usleep(1) also call indirectly nanosleep(1000)
I am using g++, linux. Any help or insight will be great and thanks in advance .