The sleep functions nanosleep()
, usleep()
and select()
are not accurate on macOS. The actual sleep times are much longer than expected. For example, nanosleep(100000)
is expected to sleep for 100ms, but the actual sleep time is 175ms, The percentage of deviation is 75%, which I think the reasonable value is 20%. usleep()
and select()
have the same issue.
This issue is only happened on macOS [1]. It’s all ok on linux [2].
My test code is here [3].
In addition, all sleep functions work fine on my own Macbook.
[1] https://travis-ci.org/ygj6/verify/jobs/616467362
[2] https://travis-ci.org/ygj6/verify/jobs/616467361
[3] https://github.com/ygj6/verify/blob/master/main.c