I am working on UDP Server/Multiple Client Application.
There are multiple threads handling multiple clients.
There is one single thread which keeps on sending KEEPALIVE Messages to each active clients. Since this thread is in while(1) so CPU Usage reaches to 100%.
Since I want this functionality to go on, I have used a while(1) thread. I also tried adding a sleep after each execution of while but I don't think sleep() frees the CPU. Is there any way I can decrease CPU Usage for a specific time. e.g after a single execution of while, I can free up the CPU for like 10 secs and then continue back to while.
Please help me. Thanks a lot in advance.
sleep - Suspends the execution of the current thread until the time-out interval elapses.
And gives processor to other threads which are ready to run.
source : http://msdn.microsoft.com/en-us/library/windows/desktop/ms686298(v=vs.85).aspx
So, just sleep does it all you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With