Skip to content

Instantly share code, notes, and snippets.

@bitsmanent
Created May 3, 2017 18:03
Show Gist options
  • Select an option

  • Save bitsmanent/7dda96e85c6c733a74191ada7805cd6a to your computer and use it in GitHub Desktop.

Select an option

Save bitsmanent/7dda96e85c6c733a74191ada7805cd6a to your computer and use it in GitHub Desktop.
POSIX compliant replacement for usleep(2)
int
sleepu(double usec) {
struct timespec req, rem;
int r;
req.tv_sec = 0;
req.tv_nsec = usec * 1000;
while((r = nanosleep(&req, &rem)) == -1 && errno == EINTR)
req = rem;
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment