From: Bernhard Voelker Date: Mon, 20 May 2013 00:03:20 +0200 Subject: [PATCH] tests/nap.h: increase delay multiplier to avoid problems in VMs like OBS The gnulib change http://git.sv.gnu.org/cgit/gnulib.git/commit/?id=5191133e (available upstreams with >= 8.22, applied to openSUSE's coreutils package with "coreutils-gnulib-tests-fix-nap-race.patch", decreased the probability of lost races to about a third, however such problems could still be observed in virtual machines like OBS. Increasing the factor from 1.125 to 3 seems to close the race window. * tests/nap.h (nap): Change the multiplier for the delay from 1.125 to 3. --- gnulib-tests/nap.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) Index: gnulib-tests/nap.h =================================================================== --- gnulib-tests/nap.h.orig +++ gnulib-tests/nap.h @@ -126,9 +126,11 @@ nap (void) /* Multiply by 1.125 (rounding up), to avoid problems if the file system's clock is a bit slower than nanosleep's. + OBS: use 3 as multiplier to avoid this race a bit better + which is even more likely in VMs. Ceiling it at INT_MAX, though. */ - int delta = (d >> 3) + ((d & 7) != 0); - d = delta < INT_MAX - d ? d + delta : INT_MAX; + int d2 = 3 * d; + d = d2 < INT_MAX ? d2 : INT_MAX; delay.tv_sec = d / 1000000000; delay.tv_nsec = d % 1000000000; }