Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Processor greedy program

Posted on 2000-04-06
6
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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…
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 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.

715 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