In previous code, worker would exit in case it gets awoken from a condition_wait() and task queue is empty. However, there may be spurious wake up (either due to pthread itself, or to some race condition between workers) that would lead to wrongly exiting a worker before we actually exit the whole scheduler. See code for more details.