Created
May 23, 2014 23:24
-
-
Save bartgee/e430f40c3d34c62a07f7 to your computer and use it in GitHub Desktop.
cross-platform sleep function not consuming any CPU usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#ifdef WIN32 | |
#include <windows.h> | |
#else | |
#include <unistd.h> | |
#endif // win32 | |
using namespace std; | |
void sleepcp(int milliseconds); | |
void sleepcp(int milliseconds) // cross-platform sleep function | |
{ | |
#ifdef WIN32 | |
Sleep(milliseconds); | |
#else | |
usleep(milliseconds * 1000); | |
#endif // win32 | |
} | |
int main() | |
{ | |
cout << "Hi! At the count to 3, I'll die! :)" << endl; | |
sleepcp(3000); | |
cout << "urrrrggghhhh!" << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment