You can use clock_nanosleep with the TIMER_ABSTIME flag to work with absolute times instead of relative times for your sleep. This will avoid problems with the accumulation of errors and race conditions, when your program is interrupted, and another process is scheduled after receiving the current time, but before the call of sleep.
Alternatively, you can use POSIX timers ( timer_create ) with a signal handler where the signal of your choice is blocked in all threads except yours, or delivered by timer in a new thread that signals a state variable or semaphore, your thread is waiting.
source share