Fix a busy loop on BSD and Mac OS