Description
On Apple platforms, pthread_cond_clockwait
isn't available, but pthread_cond_timedwait_relative_np
is. This function takes the same args as pthread_cond_timedwait
, but treats the timespec
arg as relative to the time of the call instead of relative to the UNIX epoch.
The underlying syscall takes a relative time, so pthread_cond_timedwait
is implemented by subtracting the passed-in value from __gettimeofday
, so there's no particular advantage to libpthread perform that subtraction instead of doing it ourselves when relevant (and passing a relative time all the way through in cases like wait_for
calls). This would avoid a race condition where the system time could be updated between when we internally generate an absolute time and when libpthread reads it to subtract.
pthread_cond_timedwait_relative_np
was introduced in macOS 10.4 and iOS 2.0, so there shouldn't be any substantial version-support-conditional issues to worry about here.