Re: A timeout with microsecond precision?



Yueh-Wei Hu wrote:

I noticed that g_timeout_add() using an argument with millisecond
precision.

However, I want to specify an callback function to be called every 30
microseconds.

Does glib offer this facility?
Or how could I achieve this in gtk?

I also noticed that Qt offers its timer with microsecond precision.
Why does glib offer one with millisecond precision?

Just because the API supports microsecond resolution this doesn't mean
that you can actually achieve microsecond resolution. Although graphics
APIs usually support full 16 or 32 bit coordinates, you still can't draw
a line 30 000 pixels wide on your screen actually.

Issueing and handling 33 000 interrupts per second is a tough aim. You
won't be able to achieve this with complex multitasking operating
systems and GUIs like Unix or Windows and GTK+. I think the internal
overhead (kernel + GTK+) may be up to a hundred microseconds per call on
average machines. Precision is actually rather limited as well.

I wonder what operations you intend to perform at such a high frequency?
I believe for basically everything, except maybe measurements of some
kind, a different and less stressy strategy should be possible. You
don't intend to do drawing operations at that high rate, do you??

If you really need to perform measurements at such a high frequency with
reasonable precision you'll have to do so without GTK+ and probably also
without the OS you're used to (Unix / Windows / Mac). You may need to
use either DOS (if you're on an x86 PC and like simplicity) or a modern
RTOS (Real Time Operating System). Those are specifically designed for
low latency operations. Many of them are more or less Unix-like but they
provide only subsets of Unix features. They usually don't provide GUIs
at all. Unfortunately most genuine RTOSes are commercial.

For many articles about realtime programming and issues, see:
http://www.eventhelix.com/RealtimeMantra/Basics/

Limitations of Linux (mostly true also for Windows) are outlined here:
http://www.linuxgazette.com/node/view/115
(Note the given name of the Linux author  :-)  )

Linux-based realtime solutions (commercial + non-commercial):
http://www.linuxdevices.com/articles/AT8073314981.html



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