reliable implementation of sleep