portable implementation of sleep