30 lines
566 B
C++
30 lines
566 B
C++
|
|
#include <iostream>
|
||
|
|
#include <thread>
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
void cpuKiller(){
|
||
|
|
int* p;
|
||
|
|
while(p == p){
|
||
|
|
(*p++)+1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(){
|
||
|
|
unsigned int cores = std::thread::hardware_concurrency();
|
||
|
|
std::cout << "cores: " << cores << std::endl;
|
||
|
|
|
||
|
|
std::vector<std::thread> threads;
|
||
|
|
//threads.reserve(cores);
|
||
|
|
|
||
|
|
for(int i = 0; i < cores; i++){
|
||
|
|
std::thread t(cpuKiller);
|
||
|
|
threads.push_back(move(t));
|
||
|
|
}
|
||
|
|
|
||
|
|
std::cout << threads.size() << std::endl;
|
||
|
|
|
||
|
|
for(int i = 0; i < cores; i++){
|
||
|
|
threads[i].join();
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|