in reply to Wakeup: event-loop system

Replace:

while (time<($tempo_inicial_interno+1)){ #não faz nada enquanto não transcorrer 1 segundo #en: waits 1 second };

with:

sleep 1;

See sleep


True laziness is hard work

Replies are listed 'Best First'.
Re^2: Wakeup: event-loop system
by Anonymous Monk on Mar 01, 2009 at 05:09 UTC
    Thank you! Sleep 1 has decreased about 50% of clock consumption.
    Do you think the code is ok now?

      A similar solution is required fro your second loop - put a sleep in it. As it stands the loop will run just as fast as it can output stuff with print. That will be slower than an empty loop, but still pretty fast.

      Another issue is that there is no way of stopping the 'alarm' loop. At the very least you should replace the while (1) with a down counter so it stops by itself eventually.


      True laziness is hard work