Is millis() OK to use for a timeout feature for I2C?

Are there any drawbacks to using millis() like such

timeOut = 1000; // 1 second
unsigned long x = millis() + timeOut;
while(waiting for interrupt)
{
  if(millis() >= x){break;}
}

as a timeout function or is there a better way of doing it?

More specifically I want to build a user defined timeout function into my I2C library to prevent and recover from lockups on the I2C bus.

Addition operations involving millis() should not be performed. There is almost always a way to write the code using subtraction operations, instead, which will work when millis() rolls over. Adding to the output of millis() just before it rolls over will result in a small number that you are then testing with respect to a large number.

timeOut = 1000; // 1 second
unsigned long startTime = millis();
while(waiting for interrupt)
{
if(millis()-startTime >= timeOut){break;}
}

As PaulS says, ( (later time) - (earlier time) ) will yield a valid result if the times occur across the FFFF FFFF to 0000 0000 rollover.
Try it using windows calculator in scientific view mode, ignoring anything above the 8 characters, just like the Arduino does for an unsigned long.

Thanks guys.

Do you think there would be any concerns with the amount of time that the global interrupts are disabled from using millis? I realize that they're only disabled for a few clock cycles but since it's a large portion of the code in the loop I worry that the short time will add up over time.

I think only you can answer that.

Is I2C considered hung if the slave does ACK in the bit space at the end of a transfer?

wayneft:
Do you think there would be any concerns with the amount of time that the global interrupts are disabled from using millis? I realize that they're only disabled for a few clock cycles but since it's a large portion of the code in the loop I worry that the short time will add up over time.

It won't make any difference unless interrupts are disabled for a long time - this is because millis () uses overflow interrupts on the clock timer. Whether or not interrupts are enabled it will be accurate. The only problem would be if interrupts are disabled for so long that two (timer) interrupts were missed.

However for your application (eg. in an inner loop in the I2C library) just a simple counter should help you recover from an indefinite loop.