Mail Archives: djgpp/2001/06/13/19:45:08
Tue, 12 Jun 2001, Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:
>> >> But IMHO djgpp works better under windoze dos session, not under
>> >> dosemu :(, isn't it?
>> EZ> I wasn't thinking about DOSEmu.
>> So, Win9x DOS box is the best environment for DJGPP, isn't it?
EZ> It depends. For some uses, plain DOS with CWSDPMI is better.
Which DOS is better? Is it MS-DOS, PC-DOS, some other DOS?
>> >> I has been forced to use clock() (which works fast) instead of
>> >> time() because I need to call it many times...
>> EZ> Why do you need to call `time' many times? It's unusual that a
>> EZ> program should need that.
>> Do you know a _portable_ way to check timeouts? Time() (or
>> gettimeofday()) is portable and fast (under Linux, for example ;). So,
>> program looks like this:
>> --------------------------------------------------
>> while (!timeout()) {
>> if (do_a_piece_of_work()==SUCCESS) break;
>> }
>> --------------------------------------------------
EZ> If timeouts are the issue, you could use `alarm' or `setitimer' for a
EZ> much better and more portable code.
No, I can't use setitimer() with djgpp because setitimer() uses
uclock() which doesn't works properly under win9x, when program is in
background mode. Also I can't use alarm() because it uses setitimer()... :)
I've writed simple test for this:
----------- cat timer-ex.cc -------------
#include <iostream>
#include <unistd.h>
#include <sys/time.h>
#include <signal.h>
struct itimerval tv;
static int value=0;
void sighandler(int sig) {
value++;
}
int main ()
{
cout << "--------------\n";
clock_t start=clock();
signal(SIGALRM,sighandler);
tv.it_interval.tv_sec = 0;
tv.it_interval.tv_usec = 100000;
tv.it_value.tv_sec = 0;
tv.it_value.tv_usec = 1;
setitimer (ITIMER_REAL, &tv, 0);
do_some_work_during_20_seconds();
cout << "value: " << value << "\n";
cout << "real time: " << 1.*(clock()-start)/CLOCKS_PER_SEC << "\n";
return 0;
}
-----------------------------------------
gxx -O2 timer-ex.cc -o timer-ex.exe
-----------------------------------------
In foreground mode it prints:
value: 200
real time: 19.84
In background:
value: 12
real time: 19.84
-----------------------------------------
djdev-2.03/win95osr2
There were no CPU hogs :)
- Raw text -