473,322 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Changing process priority

Hey!

This question may be basic for you guys, but I haven't found anything
related to it in the FAQ. How do I make sure a simple while(1){} loop
(for example) doesn't consume half my CPU?

Thanks

--

Cheers,

John den Haan
joDhn[dot]haEan[at]chLello[dot]nl

Remove capital 'DEL' from above addy to obtain e-mail address
Feb 17 '07 #1
9 3034
John den Haan wrote:
Hey!

This question may be basic for you guys, but I haven't found anything
related to it in the FAQ. How do I make sure a simple while(1){} loop
(for example) doesn't consume half my CPU?
That isn't a C issue, but an OS one. So you'll have to ask on a group
dedicated to your OS.

--
Ian Collins.
Feb 17 '07 #2
In article <a7***************************@news.chello.nl>,
John den Haan <no****@nospam.comwrote:
>This question may be basic for you guys, but I haven't found anything
related to it in the FAQ. How do I make sure a simple while(1){} loop
(for example) doesn't consume half my CPU?
If you restrict your choices to those available within the C
standard, then the answer is "Don't write such a loop,
and don't let anyone else write such a loop either."

If you are willing to go outside the facilities provided by standard C,
then you are dealing with OS-specific resource
allocation policies that C doesn't know anything about. In order
to find out about those policies and how to manipulate them,
you would need to ask in a forum that deals with your specific OS.
I think you will find that it is difficult to do what you want,
even with common OS extensions. OS extensions that control
process priority -usually- are set up to change -relative-
priorities, and if there is only one task available to run,
-usually- even if you lower your process priority as far as possible,
the process will consume as much CPU as is not being used for
anything else. Though sometimes there is a "idle process" that runs
an infinite loop consuming all leftover CPU time, and if you manage to
lower your process priority to match that of the idle process,
then your process and the idle process might each average half of
the available CPU time -- but keep in mind that in such a scheme,
the whole CPU time is still being used by -something-.

In order to get a hard guarantee that your process is not going to
use half (or more) of the CPU even when nothing else is waiting to run,
you would probably need to use an OS that provided "real time"
processes and processor quanta. Common operating systems don't
provide those kind of facilities (though I don't know if Linux has
them.)
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Feb 17 '07 #3
Walter Roberson schreef:
In order to get a hard guarantee that your process is not going to
use half (or more) of the CPU even when nothing else is waiting to run,
you would probably need to use an OS that provided "real time"
processes and processor quanta. Common operating systems don't
provide those kind of facilities (though I don't know if Linux has
them.)
What I am looking for is something like the 'doevents()' call in VB
which allows one to keep the OS responsive while running my app (a
game). I mean, how do all games do it? They have to loop somewhere in
order to receive input... Or do they use some form of event-driven code?

--

Cheers,

John den Haan
joDhn[dot]haEan[at]chLello[dot]nl

Remove capital 'DEL' from above addy to obtain e-mail address
Feb 17 '07 #4
In article <37***************************@news.chello.nl>,
John den Haan <no****@nospam.comwrote:
>What I am looking for is something like the 'doevents()' call in VB
which allows one to keep the OS responsive while running my app (a
game).
As I indicated earlier, there is no standard C way to do anything like
this. To find out what can be done on your OS, you will need to
ask in a forum that knows specifics about your OS. Specific answers
here are more likely to be wrong than in your OS newsgroup -- for
one thing, you didn't even indicate which OS you are using.
(Referring to VB is not an indication that you are using Windows,
only an indication that you want functionality -like- what you see
there. And I really don't know what doevents() does, as I never
use VB and doevents() is not part of the C standard.)

>I mean, how do all games do it? They have to loop somewhere in
order to receive input... Or do they use some form of event-driven code?
Games use OS specific mechanisms, which are going to vary from OS
to OS. The mechanisms I would use on my OS are probably quite different
than the mechanisms you would use on whatever OS you are using
(the OS I use isn't very common.)
--
Programming is what happens while you're busy making other plans.
Feb 17 '07 #5
On Sat, 17 Feb 2007 05:18:35 +0100, John den Haan <no****@nospam.com>
wrote in comp.lang.c:
Walter Roberson schreef:
In order to get a hard guarantee that your process is not going to
use half (or more) of the CPU even when nothing else is waiting to run,
you would probably need to use an OS that provided "real time"
processes and processor quanta. Common operating systems don't
provide those kind of facilities (though I don't know if Linux has
them.)

What I am looking for is something like the 'doevents()' call in VB
which allows one to keep the OS responsive while running my app (a
game). I mean, how do all games do it? They have to loop somewhere in
order to receive input... Or do they use some form of event-driven code?
Walter went over the top with his discussion of your off-topic
question. There is absolutely no way to do what you are asking about
in standard C, and that is what is discussed here.

There might be a way to do this using non-standard extensions on your
particular platform, but that has nothing at all to do with the C
language.

Based on your comment, I suggest asking in a Windows group like
news:comp.os.ms-windows.programmer.win32, or searching Microsoft's
MSDN web site.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Feb 17 '07 #6
John den Haan wrote:
What I am looking for is something like the 'doevents()' call in VB
which allows one to keep the OS responsive while running my app (a
game). I mean, how do all games do it? They have to loop somewhere in
order to receive input... Or do they use some form of event-driven code?
Whatever library you are using to get input should provide functions to
wait for the next event or something similar. For example, in the Simple
DirectMedia Layer (SDL) you can use the function:
int SDL_WaitEvent(SDL_Event *event);

There is also an unconditional delay function that will not return as
soon as an event occurs:
void SDL_Delay(Uint32 ms);

These provided functions will generally release the processor to the
operating system wherever possible.

--
Simon.
Feb 17 '07 #7
John den Haan said:
Hey!

This question may be basic for you guys, but I haven't found anything
related to it in the FAQ. How do I make sure a simple while(1){} loop
(for example) doesn't consume half my CPU?
By not putting one into your program.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 17 '07 #8

you can have your program block and wait for a signal instead of just
loop infinitely.

Feb 17 '07 #9
ma*****@gmail.com wrote:
you can have your program block and wait for a signal instead of just
loop infinitely.
Please quote context. Yes, this is a good method but Standard C
provides no mechanism to accomplish this.

Feb 18 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: AlanR | last post by:
Hi, I have to implement(or possibly acquire) a queue that manages priorities. Low priority elements cannot get lost in the queue indefinitely if there is a sustained, constant flow of high...
0
by: wtfhits | last post by:
I'm writing my own task manager as I often change process priorities but have gotten myself into trouble on several occasions. I have discovered by keeping csrss.exe and explorer at the equal highest...
6
by: Ganesh | last post by:
Is there a utility by microsoft (or anyone) to force garbage collection in a process without have access to the process code. regards Ganesh
77
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the...
4
by: Chad Crowder | last post by:
I've taken a look at this article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp12282000.asp which someone posted a month or so ago regarding setting up SQL...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.