> >> But whatever, using usleep(1000) should be fine in any case. > > MG> It depends what you are trying to achieve. It's ok if you want to > MG> suspend program execution for at least 1 millisecond (where "at least" > MG> may mean "far more than"!) > > What I wanted was: allow a task switch, but don't exceed 1000 HZ on > systems that would be able to.
Usleep(1000) is a terrible way to allow a task switch. The Linux kernel will do a task switch whenever it's appropriate. The buzzword is "fully preemptible". It's not like a 1980's Macintosh, where applications had to explicitly task switch or the kernel would never regain control. You don't need to tell Unix or Linux; it's automatic. So what are you *really* trying to do here? Is there some other task that you want the kernel to run? If so, send it a message; write a byte to a socket or FIFO that that task is listening on; etc. What you *do* need to tell the Linux kernel when you sleep is "when is the next time my current task will have some useful work to do?". You tell it that by the duration of your sleep request. If you don't know when there'll be more work to do, then don't sleep at all. Instead, do a system call like read() or select() or poll(), which will put you to sleep until something interesting happens on one of your file descriptors. The whole Linux community is going around cleaning up old code that does things like wake up 1000 times a second for no reason. Besides the inefficiency and ugliness of that approach, it also burns power for no reason. Many CPUs will slow their clocks and save power when lightly loaded. The OLPC will actually power off its CPU chip if it knows you'll be sleeping for at least a few seconds. It can't do that for a thousandth of a second -- and it has no way to know that your code will go right back to sleep when awakened. Here are some examples of other people cleaning up such code recently: http://www.linuxpowertop.org/ http://www.linuxpowertop.org/known.php https://ols2006.108.redhat.com/reprints/jones-reprint.pdf "Why userspace sucks -- Or 101 Really Dumb Things Your App Shouldn't Do" http://blogs.gnome.org/desrt/2006/07/27/burning-cpu-and-battery-on-the-gnome-desktop/ http://dev.laptop.org/ticket/82 "Look for misbehaving userspace apps." Let's write gnash cleanly and efficiently, rather than using kludges that others will just have to clean up after us. John _______________________________________________ Gnash-dev mailing list [email protected] http://lists.gnu.org/mailman/listinfo/gnash-dev

