View Single Post
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#5
Originally Posted by phil128 View Post
Cheers for your reply. Yea i'll be wanting real time updates, but my main concern is avoiding infinite loops or big loops as much as possible.

The problem i think about using usleep is that it'll halt execution for a period of time, but i will require the function to re-execute after a period of time. I can achieve what i want with loops, but as we all know it's nasty to do so.
I'm not sure if I follow your reasoning here.

Code:
while(1) {
  get_and_send_sample();

  usleep(DELAY);
}
Why is this bad? If all you want to do is this, a loop is the easy and straight forward way to do it. If the application on the N900 is running a GUI, use a timer in GTK+/Qt instead.

A process that uses usleep will not be scheduled at all until enough time has passed which, I assume, is your goal.