Here is a view from an old guy who grew up with DOS, and only writes windows console programs because you pretty much have to these days.
In my experience (XP32), "sleep" is indeed not very accurate and usually returns late by about
10 to 20 milliseconds. On very rare occasions it returns a little early.
This is good enough for a lot of things where you need a delay, and I never thought of improving the accuracy of it.
On the laptop that I write my software on, Windows steals time in chunks of about 16 milliseconds, and it can and do that whenever it feels like it. This suspiciously corresponds to
60 Hz, but okay, it is what it is.
It all depends on what the "sleep" is for.
One can use a delay in case a piece of hardware needs some recovery time, but I don't think that a "delay from now" is a good way to get something to pace at regular constant intervals.
Over time, the intended interval can really start to drift.
One of my programs reads a few GPIB instruments at regular intervals for long term (days)
monitoring of things.
For this, I have used a "target time" approach.
The target time for the next instrument loop is set based on the target time of the previous
loop.
The instrument loop checks the keyboard (yeah folks, it's a terminal app..) in between dealing with the instruments one by one. When the instrument loop is done, I call a wait loop which
fills the remaining time with keyboard checks and other updates until "now" is greater or equal
to the target time, after which a new target time is calculated.
Although the individual time stamps of the instrument loops can still be off by a few milliseconds, the long term stability of the time interval is very good.
It does the job without delving into threads and event handlers, so it's good enough for me.
It gets easy once you realize that a "tdatetime" is a double precision float which counts in days.
You can actually do direct math with time without the need of specialized "time manipulation" functions.
Sander