Re: How g_timeout_add works?



"ΉΛμΟ" wrote:
> I wonder if anyone know how the function 'g_timeout_add' works.
> I wrote a little test like this:
> 
> /* test.cc */
> #include <glib.h>
> #include <iostream>
> 
> gboolean
> callback (gpointer data) {
>         cout << "called" << endl;
>         return TRUE;
> }
> 
> int
> main() {
>         g_timeout_add(1000, callback, NULL);
>         while (1);
> }

Hi, timeouts are not like interrupts. They are callbacks triggered by
g_main() when it has some spare time. There's some stuff in the glib
reference about this:

http://developer.gnome.org/doc/API/glib/glib-the-main-event-loop.html

If you use g_timeout_add() in a real program (one which uses g_main() or
gtk_main()), you'll find it works.

John
--
John Cupitt, john.cupitt@ng-london.org.uk, +44 (0)20 7747 2570
VASARI Lab, The National Gallery, Trafalgar Square, London, WC2N 5DN




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