// Worker Thread pseudo-code
void fn()
{
for(;;)
{
lock = do_lock();
while (is_empty(queue))
{
wait_for_condition(lock); // releases lock while waiting on condition
// lock is regained here.
}
item = pop_queue(queue);
do_unlock(lock);
do_work(item);
}
}
It WILL happen, and more frequently that you think it can. For the only reason that indeed, machine are now so fast that they do millions of stuff very fast, so it statistically improve they number of time it can happen.
You obvisouly dont care tht much about consistancie in calculation as on a mud, it obviously does not matter that much if you have some weird behaviour from time to time at random time, most people would not even report, it, think of a fluke and forget about it.
Hope you dont have this mindset if you ever code professionally.