Solved

Processor greedy program

Posted on 2000-04-06
6
173 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

840 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