Fix nanosleep returning negative rem

David Allsopp David.Allsopp@cl.cam.ac.uk
Tue Jul 20 15:16:16 GMT 2021


I've pushed a repro case for this to
https://github.com/dra27/cygwin-nanosleep-bug.git

Originally noticed as the main CI system for OCaml has been failing
sporadically for the signal.ml test mentioned in that repo. This morning I
tried hammering that test on my dev machine and discovered that it fails
very frequently. No idea if that's drivers, Windows 10 updates, number of
cores or what, but it was definitely happening, and easily.

Drilling further, it appears that NtQueryTimer is able to return a negative
value in the TimeRemaining field even when SignalState is false. The values
I've seen have always been < 15ms - i.e. less than the timer resolution, so
I wonder if there is a point at which the timer has elapsed but has not been
signalled, but WaitForMultipleObjects returns because of the EINTR signal.
Mildly surprising that it seems to be so reproducible.

Anyway, a patch is attached which simply guards a negative return value. The
test on tbi.SignalState is in theory unnecessary.

All best,


David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Ensure-nanosleep-2-never-returns-negative-rem.patch
Type: application/octet-stream
Size: 1865 bytes
Desc: not available
URL: <https://cygwin.com/pipermail/cygwin-patches/attachments/20210720/05fb7611/attachment.obj>


More information about the Cygwin-patches mailing list