From: Torsten Dreyer Date: Thu, 6 Aug 2015 19:47:01 +0000 (+0200) Subject: Prevent 100% CPU usage for FGCom standalone X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7294999f351c3c178685e9768a8110da24de23ca;p=flightgear.git Prevent 100% CPU usage for FGCom standalone Kévin Seroux: As reported here (http://forum.flightgear.org/viewtopic.php?f=32&t=26629), the FGCom standalone client use 100% of the CPU when it is in OBS mode. The fact to add the shortest sleep time (1ms) has solved the problem. With this patch, I run FGCom with 1% of CPU usage instead of 100%. --- diff --git a/utils/fgcom/fgcom.cxx b/utils/fgcom/fgcom.cxx index d3cfa9c36..0a8f46d24 100644 --- a/utils/fgcom/fgcom.cxx +++ b/utils/fgcom/fgcom.cxx @@ -147,8 +147,10 @@ int main(int argc, char** argv) while(_running) { int bytes = sgSocket.recv(currentPacket, sizeof(currentPacket)-1, 0); - if (bytes == -1) + if (bytes == -1) { + SGTimeStamp::sleepForMSec(1); // Prevent full CPU usage (loop) continue; + } currentPacket[bytes] = '\0'; if( strcmp(currentPacket, previousPacket) != 0 ) {