X-Spam-Check-By: sourceware.org From: "Dave Korn" To: 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 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit 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 Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , 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 #include #include 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/