When the child process does not have any new output, calling
ChildProcess::readProcessOutput will block there with extremely high CPU utilization (occupying an entire logical core).
Observing the implementation of this method, I found that in line 451 of the
ChildProcess::ActiveProcess::read method (in
juce_win32_Threads.cpp), when the child process has no new output to read, the method calls
Thread::yield to yield the time slot of the current CPU. But when there are not many other tasks currently being executed in the system (for example, in a server environment), doing so is no different from an empty loop without any rest. If you change this line to “
Thread::sleep(1);”, the CPU load will drop instantly.
Can you see if such a solution is reasonable, or do you have a better solution?
In short, I hope this problem can be solved. The current implementation with such a high CPU usage is not acceptable.