Skip to content

Instantly share code, notes, and snippets.

@bartgee
Created May 23, 2014 23:24
Show Gist options
  • Save bartgee/e430f40c3d34c62a07f7 to your computer and use it in GitHub Desktop.
Save bartgee/e430f40c3d34c62a07f7 to your computer and use it in GitHub Desktop.
cross-platform sleep function not consuming any CPU usage
#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