I happened to read the pg_usleep() code recently. I'm wondering if we could implement it using the posix function nanosleep(), instead of by select().
nanosleep() is designed with higher time resolution, besides it provide remaining time if is interrupted by signal so that pg_usleep() could be implemented more accurately. The code for pg_usleep() could be similar like this: while(nanosleep(&req,&req)==-1 && errno == EINTR) continue; or combine with clock_gettime() to control the sleep time more accurately. Regards, Paul