Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Processor greedy program

Posted on 2000-04-06
6
Medium Priority
?
180 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 300 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

824 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