Created
September 22, 2023 21:54
-
-
Save jepler/bf08a9b49fc3310c9edf937ebda23c89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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