Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a program sleep without using too much cpu??

Status
Not open for further replies.

metamorphy

Programmer
Dec 16, 2001
34
US
Is there a better way to do what I'm trying to do here? This program will only compile as a DOS .exe on my old Microsoft c++ compiler (New c++ doesn't support far??). I'm trying to write a function in C that will "sleep" for a certain length of time without using very much sytem resources. Am I on the right track at all?? I've heard of sleep() in C++ but I was trying to use only C. Whats the best way??


#include <dos.h>
#include <bios.h>
#include <stdio.h>
#include <math.h>
#include <conio.h>

#define TIME_INTERRUPT 0x1C

void (_interrupt far *old_isr)();

long counter =0;
int seconds=0;

void _interrupt far timer(void){
counter++;
if(counter > 19){counter = 0; seconds++;}
old_isr();
}

void main(void){

old_isr = _dos_getvect(TIME_INTERRUPT);

_dos_setvect(TIME_INTERRUPT, timer);


while(!_kbhit()){

if(counter >=18){counter = 0; seconds++;
printf(&quot;time elapsed is %d seconds\n&quot;, seconds);
}
else{}

}
_dos_setvect(TIME_INTERRUPT,old_isr);
}
 
hi,
I have found
void Sleep( DWORD milliseconds ) ;
on my dev env.

What is different from &quot;old&quot; and now, are the operating
system. The program I see above, I belive was a TSR or similar (I was no expert in those things )

If today you are working at a NO DOS OS, you don't need
such type of programming ( in WNT you cannot access low
level function of BIOS ).

Each task (process, thread, ... ) that is wating for something ( keybord I/O,WIN message, ecc ) does not enter in CPU pool process: check it using task manager.

BYE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top