Fake sleep

I have updated the branch with cheery-picked changes and reworked the __APPLE__ related part.
Now it seems to work fine on Linux and OS X 10.8, too.