|
-
July 6th, 2006, 04:34 AM
#1
Worker thread -> 99% cpu usage..
Hi,
I have a dedicated thread in my program that always polls the parallel port in 1ms intervalls. The problem is that I have it in a continuous while-loop and the cpu usage is going to 99%.
I tried inserting a "sleep(x)" with x being anything between 0-5, but the problem is that sleep uses the system timer and that has a 15ms resolution, so even a sleep(0) can wait up to 15 milliseconds. I used the Performance Counter to verify that.
Is there a way to prevent the thread from hogging all the cpu ?
-
July 6th, 2006, 05:08 AM
#2
Re: Worker thread -> 99% cpu usage..
I think you should investigate if your problem can be solved by WaitCommEvent or WaitForSingleObject functions.
-
July 6th, 2006, 06:18 AM
#3
Re: Worker thread -> 99% cpu usage..
Thanks for the advice, but I looked them up and don't think my problem can be solved by those functions. At least I don't see how...
-
July 6th, 2006, 09:00 AM
#4
Re: Worker thread -> 99% cpu usage..
Hi There,
I think you can try SetThreadPriority, set to a low level so it should let other applications allocate processing power if needed. However with 0-5ms delay, I think it is very much likely that your processor will always be busy even when none of the more important threads allocate something since in that case the port scanner will.
Cheers
-
July 6th, 2006, 09:23 AM
#5
Re: Worker thread -> 99% cpu usage..
I think it's a bad idea to loop continuos inside a thread, it is bound to consume 99% of CPU.
You can try using Sleep(10) let let other threads run well.
Regards,
Ramkrishna Pawar
-
July 6th, 2006, 09:32 AM
#6
Re: Worker thread -> 99% cpu usage..
 Originally Posted by Krishnaa
I think it's a bad idea to loop continuos inside a thread, it is bound to consume 99% of CPU.
You can try using Sleep(10) let let other threads run well.
a ::Sleep(10) would violate his constraint, wouldn't it:
 Originally Posted by Zaph-0
I have a dedicated thread in my program that always polls the parallel port in 1ms intervalls
-
July 6th, 2006, 09:44 AM
#7
Re: Worker thread -> 99% cpu usage..
 Originally Posted by Alin
a ::Sleep(10) would violate his constraint, wouldn't it:
Sure it will violate. I am suggesting an adjustment to requirement.
One should have saperate program to poll such tight interval, a normal program with other tasks to do can not handle pressure of having a dominating thread.
Regards,
Ramkrishna Pawar
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|