Mir

Code review comment for lp:~alan-griffiths/mir/fix-1201436

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

You need to retest your conditions after a wait returns. So:
    if (received < expecting)
        wait_condition.wait_for(lock, limit);
should be:
    while (received < expecting)
        wait_condition.wait_for(lock, limit);

This is for two reasons:
  1. Some other thread could be waiting too, and racing against you. So you need to recheck the condition via a while loop after the wait returns (and when you have regained the lock) to verify the condition is really met, and you didn't lose a race.
  2. Historically OS wait functions could return prematurely (eg signals interrupting) so needed sanity checking. But I don't think this would still be true in the C++11 implementation... ?

review: Needs Fixing

« Back to merge proposal