i have an application with 4 threads from which 2 are event based and 2 are not event based.
the problem is i have to isolate the 2 non event based threads in which while(1) loop is executing that takes a huge cpu usage and this usage reaches even up to 100%,
i think making these threads isolated can reduce the cpu usage,
will it be a good idea, if there is any other method plz refer me.
and i also want to know how to isolate the threads.
thanx in advance.
As a general rule, you rarely want to simply reduce the CPU usage. While you certainly can do so (e.g., by sleeping for a while on a semi-regular basis) it won't really accomplish much. Assuming, of course, that the threads are doing something useful with the CPU time, reducing CPU usage will simply stretch the computation over a longer period of time.
To derive real benefit, reduce the priority of the CPU-intensive threads. This allows the threads to finish their computation as quickly as possible as long as they're the only threads that are ready to run. At the same time, it also means that the lower-priority threads will consume absolutely no CPU time1 as long as there are any higher-priority threads that are ready to run.
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