I need to use the nanosleep function in my user-space threads library to achieve waits of the approximately desired amount, as it can save the remaining time in case of an interrupt by async signals. I use SIGALRM to switch threads preemptively; therefore, it is important to consider the possible side effects of using non-reentrant functions. For that reason, in case a nanosleep call is interrupted by a thread switch and it is called again from another thread or signal handler, I wonder if this situation would cause problems or not.
Apparently, nanosleep function is not async-signal safe by as it is not listed here; however, sleep(3) is said to be async-signal safe. On the other hand, sleep(3) seems to be implemented using nanosleep on Linux. Can I take this as proof that nanosleep is safe for what I am trying to achieve?
EDIT: According to this resource, it is indeed AS-safe.