turn if into while for spurious wakeup protection