Skip to content

Instantly share code, notes, and snippets.

@jepler
Created September 22, 2023 21:54
Show Gist options
  • Save jepler/bf08a9b49fc3310c9edf937ebda23c89 to your computer and use it in GitHub Desktop.
Save jepler/bf08a9b49fc3310c9edf937ebda23c89 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <time.h>
#define clocksrc CLOCK_REALTIME
int main() {
struct timespec ts;
clock_gettime(clocksrc, &ts);
printf("Starting at %9ld.%09ld\n", (long)ts.tv_sec, (long)ts.tv_nsec);
ts.tv_nsec = 0;
ts.tv_sec += 1;
printf("Deadline is %9ld.%09ld\n", (long)ts.tv_sec, (long)ts.tv_nsec);
while ( clock_nanosleep(clocksrc, TIMER_ABSTIME, &ts, &ts) != 0)
/* NOTHING */ ;
clock_gettime(clocksrc, &ts);
printf("Returned at %9ld.%09ld\n", (long)ts.tv_sec, (long)ts.tv_nsec);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment