Skip to content

Instantly share code, notes, and snippets.

@YigWoo
Last active December 28, 2015 02:49
Show Gist options
  • Save YigWoo/7430699 to your computer and use it in GitHub Desktop.
Save YigWoo/7430699 to your computer and use it in GitHub Desktop.
CPU Usage 50% solution 1 using GetTickCount()
#include <boost/thread.hpp>
#include "windows.h"
#define INTERVAL 10
void infiniteLoop() {
while (1) {
DWORD startTime = GetTickCount();
while (GetTickCount() - startTime <= INTERVAL)
;
boost::posix_time::millisec sleepTime(INTERVAL);
boost::this_thread::sleep(sleepTime);
}
}
int main() {
boost::thread thread1(infiniteLoop);
boost::thread thread2(infiniteLoop);
thread1.join();
thread2.join();
char c;
std::cin >> c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment