So, I have a long-running computation that pretty much goes like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
void main(void)
{
std::deque<std::thread> thread;
const size_t threadCount = std::min(MAX_THREAD_COUNT, std::thread::hardware_concurrency());
for (size_t threadId = 0U; threadId < threadCount; ++threadId)
{
thread.emplace_back(thread_routine, threadId);
}
while (!completed)
{
std::this_thread::sleep_for(std::chrono::minutes(1));
print_progress(); // <-- this will print a time-stamp and the progress in percent to the terminal
}
while (!thread.empty())
{
thread.front().join();
thread.pop_front();
}
fputws(L"Finished.\n\n", stderr);
}
|
Thought our new Mac mini "M2" would be good device to let this run for a couple of days, because it is quiet and pretty efficient.
Only problem is that, after a while, the computation – or at least the progress update – seems to "hang" for some reason.
At the beginning, the progress update will be printed (roughly) once per minute, as is expected.
However, after about ~20 minutes or so, I noticed that it often won't print any progress update for more than 10 minutes!
In the "Activity Monitor" (task manager) I still see 100% load on all 10 CPU cores... 🤔
The very same code running on my Windows (built with MSVC) or Linux (built with G++) machine does
not exhibit this behavior. Progress updates come in regularly once per minute, even if I let the program run for several hours.
So, any idea what is going on here? Does MacOS somehow "throttle" my long-running process for some reason?