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