Sleep functions are not accurate on macOS

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

Is macOS in travis-ci a physical or virtual machine?
Is there any error in the clock of virtual machine?

Possible reason:

I always get success regardless of whether app nap is enabled or not on my Macbook. And I don’t known how to turn on/off app nap on travis-ci, So it is unable to verify the reason. Can you give me some advice? Thanks.

@BanzaiMan Can you take a time to look in this issue? Many thanks!

Looks like it is disabled already

If this are used by travis-ci of course

1 Like