How to keep a program from hogging the processor?

The forum for all of your Freebasic needs!

Moderators: Pete, Mods

Post Reply
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

How to keep a program from hogging the processor?

Post by Mentat »

I was just wondering how to run make FB programs in the back ground. Specifically, math intensive programs that run for extensive periods. I had to run one overnight because everything else was getting unresponsive or ridiculusly slow.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
BadMrBox
Veteran
Posts: 86
Joined: Tue Feb 28, 2006 12:19 pm

Post by BadMrBox »

Add a sleep in your main loop too keep it from hoggin all the processor power.
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

Alright. Is there a way to directly ask for a fixed percentage? Such as constantly using 3%?
For any grievances posted above, I blame whoever is in charge . . .
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

If he went to bed?

Post by burger2227 »

Am I missing something here? The program apparently ran for a long time. Sounds better than sitting there waiting for answers!

I anticipated a SLEEP kind of answer, but once you start something, ya gotta finish it!

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
Kiyotewolf
Veteran
Posts: 96
Joined: Tue Apr 01, 2008 11:38 pm

Fixing your CPU

Post by Kiyotewolf »

Tell your program to periodically take a coffee break.

Your program will only hog CPU cycles if it constantly requests access to something via IRQ, DMA, or the FPU (486+1) math co-processor chip.

That means.. make it do something stupid like twirl a cursor..

- / | \ - / | \ .. or do a null loop.. something long enough that the CPU will not try to optimise it and kill the whole point of slowing down.. or something creative that is just plain mundane.

Simple.

Check against clock cycles or whatever timer you can find to interrupt your processing that way.
Banana phone! We need more lemon pledge. * exploding fist of iced tea! * I see your psycho cat and counter with a duck that has a broken leg, in a cast.
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Re: If he went to bed?

Post by Mentat »

burger2227 wrote:Am I missing something here? The program apparently ran for a long time. Sounds better than sitting there waiting for answers!

I anticipated a SLEEP kind of answer, but once you start something, ya gotta finish it!

Ted
These problems can run for a long time. So, I want to be able to use the computer in the mean time for other things, such as other problems.

Such as: Find the product of the pythagorean triple that sums up to 1000.
Ohhhhhhhh......I'm an idiot. Never mind that, but some of the other problems do take some time. I just want answers. And my question on how to keep it quiet was answered well.

They're from the Euler project, if that means anything to you.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Euler

Post by burger2227 »

OK, a timed SLEEP can allow the program to share the processor. Even with Windows. The best scenario would be to be in pure DOS.

SCREEN 0 is probably the best option to run 2 QB programs at once.

I saw the Euler project before, but I figured that it was a waste of time. Have you learned anything? If you are happy then I am too!

Have fun,

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
BadMrBox
Veteran
Posts: 86
Joined: Tue Feb 28, 2006 12:19 pm

Post by BadMrBox »

Code: Select all

do
sleep 25,1
loop 
Will make your program wait for 25ms every cycle making it quite much less cpu craving.
I anticipated a SLEEP kind of answer, but once you start something, ya gotta finish it!
What you mean?
Post Reply