Recalculation of timeouts with g_timeout_add
- From: Mitko Haralanov <mitko qlogic com>
- To: gtk-app-devel-list gnome org
- Subject: Recalculation of timeouts with g_timeout_add
- Date: Thu, 15 May 2008 16:15:37 -0700
I have a question about g_timeout_add's timeout recalculation.
Currently, the next call time is calculated based on <time of callback
thread start> + <timeout given to g_timeout_add>. This means that if I
call g_timeout_add with a timeout of 20*1000 msecs (20 seconds) and my
callback takes 10 seconds to complete, my callback will be called 10
seconds after it completes. Here is an example:
#include <gtk/gtk.h>
#include <glib.h>
#include <time.h>
#include <stdio.h>
gboolean callback (gpointer data) {
int timeout = *((int *)data);
printf ("callback called at: %lu\n", time (NULL));
sleep (timeout);
printf ("callback returns at: %lu\n", time (NULL));
return TRUE;
}
int main (int argc, char **argv) {
int timeout = 10;
gtk_init (&argc, &argv);
g_timeout_add (20*1000, callback, (gpointer)&timeout);
gtk_main ();
}
will produce this:
callback called at: 1210893003
callback returns at: 1210893013
callback called at: 1210893023
callback returns at: 1210893033
callback called at: 1210893043
What I would to happen is that my callback is called 20 seconds after
it returns, not 20 seconds after it is started.
How can I accomplish this?
--
Mitko Haralanov
==========================================
What this country needs is a good five cent microcomputer.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]