开发者

making an isolated process via c program in windows xp?

开发者 https://www.devze.com 2023-01-04 18:36 出处:网络
i have an application with 4 threads from which 2 are event based and 2 are not event based. the prob开发者_如何转开发lem is i have to isolate the 2 non event based threads in which while(1) loop is

i have an application with 4 threads from which 2 are event based and 2 are not event based.

the prob开发者_如何转开发lem 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.

  1. Well, if you want to get technical, Windows has an anti-starvation mechanism that lets lower priority threads that are ready to run get a minuscule bit of CPU time, but it's so little that it normally won't affect higher-priority threads enough to notice.


If you make your threads sleep for a short amount of time after each loop, that should reduce CPU load.

0

精彩评论

暂无评论...
验证码 换一张
取 消