Re: Using gtk_timeout_add with very short timeperiods (45 ms)



>I'm trying to write a program that reads a hardware port every 45 ms,
>it's a CID application with a piece of hardware attached to the
>parallell port.

>I guess another solution is to have a separate thread blocking on the
>hardware. However, I'm still interested in the answer to the question above.

default unix system timer resolution is limited by the timer interrupt
frequency set by the kernel. On a conventional Linux box, that
defaults to 10ms. So, first of all, you will never get good results
unless your period is a multiple of 10ms.

secondly, timer functions are called from GTK's main loop, where they
also compete for time with X event handling, with all that implies
about the call chains you set up with your GTK event handlers. as a
result, you will often get sloppy timing just because some stuff done
by an event handler took a bit too long. disk i/o is a favorite
example, but there are lots of others.

if you really want to poll with 45ms period, you can't use the unix
system timer (which is what gtk_timeout_add() *mostly* relies
upon). you need to use some other method. if you are using a kernel
version 2.3.41 or above, the real time clock driver will support async
i/o, allowing it to be used as a timing source for any power-of-2
frequency between 64 and 8192Hz. i'm afraid that as far as i know,
nobody has back-ported my changes to the RTC driver to support this
into any of the 2.2 series kernels.

--p




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