delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/14/16:15:26

From: Tim Updegrove <tupdegrove AT lucent DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: uclock failure at midnight
Date: Wed, 14 Jun 2000 15:59:52 -0400
Organization: Lucent Technologies
Lines: 74
Message-ID: <3947E438.814C7F47@lucent.com>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1000613132717 DOT 16888R-100000 AT is>
NNTP-Posting-Host: pai830tupdegrove.micro.lucent.com
Mime-Version: 1.0
X-Mailer: Mozilla 4.61 [en] (Win95; I)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I'm running v2.03.  The failure only occurs when booting directly to MS-DOS
(it doesn't fail in a dos box under Win98SE).  Here is small test case.  Use
the "time" command to set the time 15 seconds or so before midnight and run
the test.
=====================================
#include <stdio.h>
#include <time.h>

int delay_clock(unsigned long max_ticks);

int main(int argc, char *argv[]) {

 int status;
 unsigned i;

  for (i=0; i< 20*1000;i++) { //20 sec
    status = delay_clock(1000);
  if (status != 0) {
   printf("Error: delay_clock has failed\n");
   exit(1);
  } // error
 } //for


  return 0;

} // main

int delay_clock(unsigned long max_ticks) {

  unsigned long int
    diff_time;

  uclock_t
    starttime,
    endtime;

  starttime = uclock();
  endtime = starttime;

  diff_time = (unsigned long int) (endtime - starttime);
  while ( diff_time < max_ticks) {
    endtime = uclock();
    diff_time = (unsigned long int) (endtime - starttime);

    if ((diff_time & 0x80000000) == 0x80000000) {
      printf("Error: uclock timer has overflowed.\n");
      printf("       starttime=%08lx, endtime=%08lx, diff_time=%08lx\n",
     (unsigned long int) starttime, (unsigned long int) endtime, diff_time);
      exit(1);
    } // crazy timer
  } /* while delay */

  return 0;
} /* delay_clock */
==================

Eli Zaretskii wrote:

> On Mon, 12 Jun 2000, Tim Updegrove wrote:
>
> > My program runs 12 seconds but if it tries to run through midnight then
> > it fails because a uclock() value after midnight is less than a uclock()
> > value before midnight.
>
> `uclock' is written to handle the midnight case, so it should work.
> Please post the shortest test program that can be used to reproduce
> the problem.
>
> What version of DJGPP is this, btw?  If it's 2.02, please upgrade to
> v2.03 where `uclock' is more reliable on Windows.
>
> Are you running this on DOS or on Windows?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019