|
Boost : |
From: Gavin Lambert (boost_at_[hidden])
Date: 2022-06-21 00:48:13
On 20/06/2022 19:10, Daggumati, Rajesh wrote:
> When I use boost sleep function, I am getting delayed response.
[...]
> output is :
> 10005
> 10006
>
> Expected ouput should be 10000 and 10000
Sleep time is always a minimum bound, not exact, and is subject to the
whims of the OS's thread scheduler. You just have to live with that.
Getting less than 10ms "drift" is actually an excellent result; on a
loaded system it may be a lot worse than that.
There are some techniques that you can use to try to smooth out sleeps a
bit (such as keeping track of the difference between requested and
actual delay and adjusting your subsequent request accordingly), but
these are rarely necessary (and are impossible to get "perfect" since
they're only reactive; and can themselves be the source of bugs,
especially in the presence of suspended power states), so they're not
recommended for general use.
The best method of compensating for this sort of thing depends on
exactly what you're actually trying to do; different goals call for
different solutions.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk