Hi,
I'd like to write a delay function for DOS (real DOS, not Win32 console). But the important thing is: The function shall not increase the processor load to 100 %. So anything like that:is completely out of the question. Because such a function would put the processor load to 100 % (50 % on a dual core, 25 % on a quad core etc.) for the duration of the loop. And I want to avoid this at all costs.Code:void delay(int milliseconds) { clock_t start = clock(); while ((clock() - start) * 1000 / CLOCKS_PER_SEC < milliseconds) { // Do nothing. } }
So, I basically need something that does the same as the Sleep function in Windows (which does not make the processor jump to 100 %), only that I need a DOS version.
Turbo C++ has a delay function, but it suffers from the mentioned drawback. And it has a sleep function that doesn't increase the processor load, but it can only wait whole seconds, not milliseconds. Also, I need the delay to work with all DOS C++ compilers and therefore cannot rely on a function that only comes with a specific compiler.
How do I solve my problem? Can this be done with normal C or C++ or do I have to use some assembler code in the function? I'd really appreciate if you could help me.



8Likes
LinkBack URL
About LinkBacks



