[so] test 6

florin chiculita the_linux_terrorist at yahoo.com
Fri Nov 16 22:33:35 EET 2007


iarasi intervin... (nesolicitat, ca si data trecuta...)

nu e mai simplu cu usleep ?
chiar daca usleep e obsolete....

void usleep(unsigned long usec);

$ cat /usr/include/limits.h | grep ULONG
#   define ULONG_MAX    4294967295UL

usleep( (unsigned long) ms * 1000) sau ceva de genu' ar trebui sa mearga ca uns...
 
Marius Nicolae <mariusn007 at gmail.com> wrote: On Nov 16, 2007 10:17 PM, Catalin Iacob  wrote:
> On Friday 16 November 2007 22:03:34 Marius Nicolae wrote:
> > Pai nici nu trebuie sa fac un sleep, am dormit deja x secunde cu
> > sleep(ms/1000).
>
> Nu prea am urmarit thread-ul fiindca s-au intins foarte tare discutiile.
>
> Dar aici gresesti. Operatorul / in C/C++ iti face impartire intreaga.
> Daca ms == 500 rezultatul 500/1000 == 0. Deci nu dormi deloc.
> Similar, daca ms == 1900, 1900 / 1000 == 1 deci in loc de aproape 2 secunde
> dormi una singura.
>
> Nu stiu daca asta e problema ta (sau daca tu erai cel cu problema :D) dar
> sleep(ms / 1000) suna gresit.

Poate asa e mai clar:

{
    sleep(ms/1000);
    usleep(ms%1000*1000);
}

Pentru ms==1900,
prima instructiune este sleep(1) - doarme o secunda
a doua instructiune este sleep(900000) - doarme 900 milisecunde
--------------
Total: 1900 ms

>
> Catalin
>
> _______________________________________________
> so mailing list
> so at cursuri.cs.pub.ro
> http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/so
>
_______________________________________________
so mailing list
so at cursuri.cs.pub.ro
http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/so


       
---------------------------------
Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cursuri.cs.pub.ro/pipermail/so/attachments/20071116/21f198df/attachment.html


More information about the so mailing list