This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project. See the Cygwin home page for more information.
[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

[B20.1] stdio and timing issues



I am having some trouble with stdin and timing.

1) It sometimes misses printing a line.
2) Whatever clock() uses for timing appears to not count the time it
waits for user input with, for example, getc.
3) Pressing Ctrl+Z for the input seems to kill stdin routines.  Ctrl+C
doesn't even kill it then.

I have B20.1 running under WinNT 4.0 SP4 with CYGWIN set to `tty' and
TERM set to `pcansi'.  I've tried the latest coolview and different TERM
settings, to no avail.

I'm including an example program below.  It does what I'd expect under
Mingw32 and DJGPP, but it has the aforementioned issues under Cygwin.

I would appreciate any help on this.  Thanks!

Brad

--- cut here ---
#include <stdio.h>
#include <time.h>

#define TWOLINES
#define EMPTYLOOP 0xFFFFFF

/* Input
   -----
   Expects the user to press Enter.

   Output
   ------
   Prints the start clock(), the end clock(), and the difference in
seconds.

   Cygwin issues
   -------------
   It sometimes misses printing the second line.  When TWOLINES is
defined,
     it usually prints both, but not always.  When it isn't defined, it
     usually doesn't print a line.  (Strange problem with stdout?)
   The end clock() printed is always nearly the same.  Defining
EMPTYLOOP
     shows that it does pause after receiving an Enter; however, it
doesn't
     appear to count the time waiting for user input.  (Different
behavior
     than djgpp and mingw32.)
   Pressing Ctrl+Z for the input seems to kill the stdin routine.
Ctrl+C
     doesn't even kill it then; I have to use Task Manager.
   */

int main()
{
 clock_t clkStart = clock();
 clock_t clkEnd;
 int i;

 i = getc(stdin);

#ifdef EMPTYLOOP
 for (i = 0; i < EMPTYLOOP; i++)
  ;
#endif

 clkEnd = clock();

 printf("%d -> %d: "
#ifdef TWOLINES
  "\n"
#endif
  "%f seconds.\n",
  clkStart, clkEnd, (float)(clkEnd - clkStart) / CLOCKS_PER_SEC);

 return 0;
}
--- cut here ---