Solved

Processor greedy program

Posted on 2000-04-06
6
170 Views
Last Modified: 2010-04-02
I have converted a C dos program to VC++ the program works Ok but it uses up all the processor resources and therefore stops timers I am using to control events.  I have done this for a final year dissertation and I have to explain why this is happing.  Does any one have any ideas or has anyone come across a site  which explains how processor resources are allocated.  I thought that as it is programed in VC++ it should have the time sharing ability of windows.
0
Comment
Question by:Richard_Eustace
6 Comments
 
LVL 3

Expert Comment

by:Iexpert
ID: 2690157
? Windoze what?
emm something else, oh yes show the bit of
code that's using the resources!!!!!!!!
0
 
LVL 22

Expert Comment

by:nietod
ID: 2690248
In windows you want to avoid code that does "bussy waiting", like loops that continually check to see of a key has been typed or that checks to see if some flag has been set.  Windows provides lots of different options for avoiding those sorts of busy waits, but we would need to know more details about your program in order to tell you what to do.

>> explains how processor resources are allocated.
This is very complex in windows because it is a mix of pre-emptive and cooperative mult-tasking.  If it was strictly pre-emptive this probably would not be as big a problem.   I recommend you loo at some opf the windows "internals" books, like "Inside Windows 95" for a description of how the multi-tasking works in windows 9x.
0
 
LVL 2

Accepted Solution

by:
tdubroff earned 100 total points
ID: 2690625
You can put any wait-for-somethings that you have inside a thread, or you can manually force the Windows Message Pump to keep pumping messages.  To do this you could insert this code inside your wait-for-something routines:

    MSG Message;

    if (::PeekMessage(&Message,NULL,0,0,PM_REMOVE)){
        ::TranslateMessage(&Message);
        ::DispatchMessage(&Message);
    }

Every time this code is called, Windows gets a chance to dispatch a waiting message.  Call it multiple times so that Windows keeps getting a chance for dispatches.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 2690807
Since this is a converted DOS program, it probably doesn't have a message pump--or need for one.
0
 
LVL 4

Expert Comment

by:pellep
ID: 2693693
You might try putting a Sleep(50) (or another short period of time) somewhere in your loop to yield execution to ther threads.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2693890
That can help in a sense, but win32 is pre-emptive, so you don't want to do that when your program has work to do.  Ans it would be best if you didn't use any CPU time when there is not work to do.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now