So what in this situation do you think he should do if tryLock() fails? And please tell me how to avoid thread starvation with tryLock() as I'm sure you will agree that using tryLock() instead of lock() creates a possibility of starving the thread.
Ok. I think about something like that:
if (mutex.tryLock(5))
{
// do something
mutex.unlock();
return true; // action succeeds
}
else
return false; //Just quit. No starving. We can try next time
if (mutex.tryLock(5))
{
// do something
mutex.unlock();
return true; // action succeeds
}
else
return false; //Just quit. No starving. We can try next time
To copy to clipboard, switch view to plain text mode
Also in other threads where we need to call the function we can use wait call with arbitrary timing. Do you agree?
Bookmarks