Hi, In the context of octave, I need to have a loop that sleeps for about 100ms then perform some action. Most of the time, the action to perform is empty so the loop is mainly sleeping. I don't expect such loop to be CPU-consuming. To build this loop in octave, I'm using octave_usleep, which calls gnulib nanosleep. I've noticed that such loop on Win32 is consuming a significant amount of CPU, about 5-6%, which is suprizing.
I've built a small example (see below) to compare the CPU usage of gnulib nanosleep and Win32 Sleep (the delay being 100ms, Sleep is good enough). When running it, I see a steady CPU usage of 5-6% when using nanosleep, and 0% when using Win32 Sleep. Is this something that can be fixed in gnulib? Or is this something I have to live with? Note that the main octave developer is not really willing to have a special case with #ifdef for Win32 in octave's code as this is the specific reason for octave moving to gnulib. Thanks, Michael. #include <config.h> #include <time.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <stdio.h> int main (int argc, char **argv) { struct timespec t1, rem; int i; t1.tv_sec = 0; t1.tv_nsec = 100000000; printf ("testing gnulib::nanosleep...\n"); for (i = 0; i < 100; i++) nanosleep (&t1, &rem); printf ("testing Win32 Sleep...\n"); for (i = 0; i < 100; i++) Sleep (100); return 0; }