delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/08/07/11:47:01

X-Spam-Check-By: sourceware.org
From: "Dave Korn" <dave DOT korn AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
References: <936e62f0708070834l7d96af4cpf497ca3f6b0c45af AT mail DOT gmail DOT com>
Subject: RE: Can't get usleep() to work, returns -1
Date: Tue, 7 Aug 2007 16:46:40 +0100
Message-ID: <015e01c7d90a$25a6d7a0$2e08a8c0@CAM.ARTIMI.COM>
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <936e62f0708070834l7d96af4cpf497ca3f6b0c45af@mail.gmail.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 07 August 2007 16:35, Neil Jansen wrote:

> I'm trying to write a serial port app with GCC.  I need to insert a
> 100ms delay between commands, and I'm trying to do with with the
> usleep() function.  When I do this it returns -1.

  http://cygwin.com/acronyms#PPAST.  It http://cygwin.com/acronyms#WJFFM.

> Is there a way to get this to work, or possibly could someone
> recommend another millisecond delay routine?

  The way to get it to work will probably turn out to be "using it correctly".
My testcase:

/artimi/chips $ cat us.c

#include <stdio.h>
#include <unistd.h>
#include <errno.h>

int main (int argc, const char **argv)
{
  int rv, dtime;
  if (argc >= 2)
  {
    dtime = atoi (argv[1]);
  }
  else
  {
    dtime = 100 * 1000;
  }
  printf ("delay %dus. Start now:\n", dtime); fflush (NULL);
  rv = usleep (dtime);
  printf ("Finished... "); fflush (NULL);
  printf ("ret val %d errno %d\n", rv, errno);
  return 0;
}

/artimi/chips $ gcc -g -O2 -o us ./us.c
/artimi/chips $ time ./us.exe
delay 100000us. Start now:
Finished... ret val 0 errno 0

real    0m0.266s
user    0m0.171s
sys     0m0.000s
/artimi/chips $ time ./us.exe  1000000
delay 1000000us. Start now:
Finished... ret val 0 errno 0

real    0m1.156s
user    0m0.171s
sys     0m0.000s
/artimi/chips $

shows usleep working with no problems, so I think the bug is most likely in
your program.


    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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