You check a condition and act later, but something else can change it in between. The fix is to make check and use one atomic step, or to act on the thing you checked. See race condition.