[gccsdk] Unixlib select bug?

Chris Johns chris at lessthan3.org.uk
Fri Mar 27 04:37:32 PDT 2020


Not sure if this is the right place to post this..

I think there is a bug in the select() timeout logic - the effect is it 
seems to ignore the tv_usec part of the timeout. Python's time.sleep 
used select to do the actual waiting, and it was found that it just 
ignored the fractional part, so sleep(0.2) would just return. In fact 
sleep (0.99) also just returns, sleep (1.0) sleeps for a second, 
sleep(1.99) also sleeps for a second..

I had a look at the logic in ul_select.c and it appears to use this to 
work out then end time..

           end = now + timeout->tv_sec * 100
             + (50000 + timeout->tv_usec) / 1000000;

However, the tv_usec part will just get end up as 0 (unless its > 
1000000, but that will get rejected by the earlier check). I think the 
problem is it's converting usec to seconds, rather than usec to 
centiseconds, so it should be:

           end = now + timeout->tv_sec * 100
             + (500 + timeout->tv_usec) / 10000;

In fact:

           end = now + timeout->tv_sec * 100 + timeout->tv_usec / 10000;

Might be enough.

Cheers,

Chris





More information about the gcc mailing list