Easy to do (loose syntax):
while(true) {
firstcheck = -1, lastcheck;
if (trylock())
return SUCCESS;
if (lastcheck == -1) {
firstcheck = getmillis(); // assume getmillis is
// expensive so we only
// do it if first trylock
// fails
yield(); // ...or sleep 1ms
} else {
thischeck = getmillis();
if (thischeck - firstcheck > timeout)
return TIMEOUT;
yield();
}
}
Logged In: YES
user_id=147739
Thank you for your request and idea.
We have considered this and we might add support for this.