Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just to be clear, in your example, because 110 is not after 150, <code>time_after(110,150)</code> should (and does) return false. From the comment:</p> <pre><code>time_after(a,b) returns true if the time a is after time b. </code></pre> <p>Also, note that the code does indeed handle wrapping around to 0. To make the following a bit easier to understand, I'll use unsigned and signed one-byte values, i.e. 8-bit 2's complement. But the argument is general.</p> <p>Suppose b is 253, and five ticks later jiffies has wrapped around to 2. We would therefore expect <code>time_after(2,253)</code> to return true. And it does (using int8_t to denote a signed 8-bit value):</p> <pre><code>(int8_t) 253 - (int8_t) 2 == -3 - 2 == -5 &lt; 0 </code></pre> <p>You can try other values, too. This one is trickier, for <code>time_after(128, 127)</code>, which should be true as well:</p> <pre><code>(int8_t) 127 - (int8_t) 128 == 127 - (-128) == 255 == -1 (for 8-bit 2's complement) &lt; 0 </code></pre> <p>In reality the type of the expression <code>(int8_t) 127 - (int8_t) 128</code> would be an int, and the value really would be 255. But using longs the expression type would be long and the equivalent example would be, for <code>time_after( 2147483648, 2147483647)</code>:</p> <pre><code>(long) 2147483647 - (long) 2147483648 == 2147483647 - (-2147483648) == 4294967295 == -1 &lt; 0 </code></pre> <p>Eventually, after wrapping around, the "after" jiffies value <code>a</code> will begin to catch up with the before value <code>b</code>, and <code>time_after(a,b)</code> will report false. For N-bit 2's complement, this happens when <code>a</code> is 2^(N-1) ticks later than b. For N=8, that happens when <code>a</code> is 128 ticks after b. For N=32, that's 2147483648 ticks, or (with 1 ms ticks) about 25 days.</p> <p>For the mathematically inclined, I believe that in general <code>time_after(a,b)</code> returns true iff the least residue (modulo 2^N) of (a-b) is > 0 and &lt; 2^(N-1).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload