Re: thread loops: prevent from 100% cpu usage?



Hi,

On Thu, 1 Jul 2004 20:49:13 +0200, F. Kater <f kater2 gmx net> wrote:
my cpu uses 100% of the power due to a loop in a thread I use. How can I
prevent from that? (The loop is waiting for a digital-I/O signal from an
external device.) 

You could try sleeping for a few milliseconds between tests. If you
can get an interrupt from the device, that's even better.

Use usleep(10000) to wait for 10 ms. Other threads will run while you sleep.

John



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]