34 lines
618 B
C++
34 lines
618 B
C++
#include <iostream>
|
|
#include <thread>
|
|
#include <vector>
|
|
#include <chrono>
|
|
#include <atomic>
|
|
|
|
std::atomic<bool> running{true};
|
|
|
|
void cpu_burner() {
|
|
while (true) {
|
|
volatile double x = 1.0;
|
|
for (int i = 0; i < 1000000; ++i) {
|
|
x += x * 0.000001;
|
|
x -= x * 0.000001;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
int cores = std::thread::hardware_concurrency();
|
|
if (cores == 0) cores = 4;
|
|
std::vector<std::thread> threads;
|
|
for (int i = 0; i < cores; ++i) {
|
|
threads.emplace_back(cpu_burner);
|
|
}
|
|
|
|
|
|
for (auto& t : threads) {
|
|
t.join();
|
|
}
|
|
|
|
return 0;
|
|
}
|