▲ | comex 2 days ago | |
There's pthread_cond_timedwait_relative_np. Looking at the implementation, pthread_cond_timedwait starts by converting the deadline to a relative timeout [1], but this is skipped if pthread_cond_timedwait_relative_np is used. Then, in the kernel, the timeout is converted back to an absolute deadline by either [2] or [3], but both of those are using Mach absolute time rather than the wall clock. Mach absolute time is monotonic. It pauses while the system is asleep, which may or may not be what you want. If need the timer to keep incrementing while the system is asleep, there's no way to do it directly with a timed wait, but you can use kevent with EVFILT_TIMER + NOTE_MACHTIME + NOTE_MACH_CONTINUOUS_TIME. [1] https://github.com/apple-oss-distributions/libpthread/blob/1... [2] https://github.com/apple-oss-distributions/libpthread/blob/1... [3] https://github.com/apple-oss-distributions/xnu/blob/e3723e1f... | ||
▲ | 2 days ago | parent | next [-] | |
[deleted] | ||
▲ | jcalvinowens 2 days ago | parent | prev [-] | |
Interesting, so it behaves more or less like pthread_cond_reltimedwait_np() in Solaris? I wonder which came first. The context is a UDP network receiver which infers packet loss after a timeout: https://github.com/facebook/netconsd/blob/main/threads.c#L15... https://github.com/facebook/netconsd/blob/main/worker.c#L526 Time while sleeping doesn't matter here. |