Solved

Processor greedy program

Posted on 2000-04-06
6
169 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

762 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

19 Experts available now in Live!

Get 1:1 Help Now