This code does not work if we only start quark with cpus <= 60:
#include <iostream>
#include <thread>
#include <vector>
#include <atomic>
std::atomic<bool> run(true);
void busy_wait() {
while (run);
}
int main() {
std::vector<std::thread> threads;
for (int i = 0; i < 60; ++i) {
threads.emplace_back(busy_wait);
}
// Let the threads run for a short duration
std::this_thread::sleep_for(std::chrono::seconds(5));
run = false;
for (auto& t : threads) {
if (t.joinable()) {
t.join();
}
}
std::cout << "All threads completed and exited." << std::endl;
return 0;
}
It seems that when main thread goes to sleep, it can not wake up forever. Do you have any solution for this problem?
This code does not work if we only start quark with
cpus <= 60:It seems that when main thread goes to sleep, it can not wake up forever. Do you have any solution for this problem?