[Asterisk-Dev] busy-wait loops in pbx_dundi

SteveK stevek at stevek.com
Fri Jun 10 04:59:40 MST 2005

On Jun 10, 2005, at 4:53 AM, Luigi Rizzo wrote:

> while applying the timeval changes, i noticed that pbx_dundi.c
> is full of busy-wait loops of the form
>     while (!some_condition) {
>         usleep(1);
>     }
> could someone comment how one avoids that this code eats 100% of the
> CPU and how high the risk is ?

The answer to that seems pretty obvious, Luigi.

Assuming that usleep works correctly (it more or less does), and the  
test for some condition takes less than a microsecond to execute (it  
surely does), then this loop won't use more than 0.1% of your CPU.


More information about the asterisk-dev mailing list