www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/06/09/15:43:24

Date: Fri, 09 Jun 1995 14:03:24 -0500 (CDT)
From: Aaron Ucko <UCKO AT VAX1 DOT ROCKHURST DOT EDU>
Subject: Re: usleep == sleep?
To: imacky AT us DOT oracle DOT com
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Organization: Rockhurst College; Kansas City, MO

>> >>sound(f); /* f is the desired frequency */
>> >>usleep(t); /* t is the duration in microseconds (1e-6 s) */
>> >>nosound();
>> >
>> >But alas, it appears:
>> >
>> >#define usleep(t)	sleep(t / 1000000)
>> >
>> >Is this still true?  Is it fixed in the latest version?  Can anyone
>> >get the suggested beeper to work?
>> 
>> DJGPP 1.12m3 has the line `unsigned usleep(unsigned)' in <djgppstd.h>.
>> What version _are_ you using, anyway?
>
>I said it *appears* as if usleep were defined that way.  I can see the
>function declaration in my version too, but usleep() *functions* as
>though it just calls sleep() as above.

Sorry about the misinterpretation.
Anyway, I wrote a simple program to test usleep(), and it seems that [at least
in 1.12m3; I don't know whether this will be true for V2 as well] usleep()
operates at a resolution of only 55ms (a number which is no doubt all too
familiar to many of us :-( ).

However, a glance at my TC++'s help file tells me that it [and DJGPP] use
delay() [in <dos.h> for both compilers] to achieve 1-ms resolution [which
should probably be good enough for most purposes].  The argument to delay()
is simply the time in milliseconds you want the program to sleep.

BTW, why isn't usleep(x) just #defined as delay(x/1000)?  1ms resolution
is certainly better than 55ms resolution...

--- Aaron Ucko (ucko AT vax1 DOT rockhurst DOT edu; finger for PGP public key) | httyp!
Geek code 2.1 [for explanation, finger hayden@ | `God's Laws' (Rudy Rucker,  
vax1.mankato.msus.edu]: GCS/M/S d(-) H s g+ p? \ _Master of Space and Time_):
!au a17 w+ v+(++) C++(+++)>++++ UL++(S+)>++++	\ 1) Be clean. 2) Follow Gary.
P+(++) L++ 3(-) E- N+(++) K- W--(---) M-@ V-(--) \ 3) Teach God's Laws.
po-(--) Y+ t(+) !5 j(++) R(-) G' tv--(-) b+++	  +---------------------------
!D(--) B--(---) e>++++(*) u++(@) h!() f(+) r-(--)>+++ n+(-) y?

- Raw text -


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