Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using futex syscall to implement sleep
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/futex.h>
futex_sleep (time_t seconds, long nanoseconds)
uint32_t futexWord = 0;
struct timespec timeout = { seconds, nanoseconds };
return syscall (SYS_futex, &futexWord, FUTEX_WAIT, futexWord, &timeout,
NULL, 0);
main ()
time_t secs = 2;
printf ("Before futex_sleep for %ld seconds\n", secs);
futex_sleep (2, 0);
printf ("After futex_sleep\n");
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.