Pregunta

I was already told to use glib but I'm not allowed to upgrade glib. So I can't use this code:

GMainLoop* loop = g_main_loop_new (NULL, FALSE);
g_timeout_add_seconds (5, mainLoop, &data);
g_timeout_add_seconds (15*60, editTree, &data);
g_main_loop_run (loop);

Is there any alternative how can I call 2 functions basing on timers? The first function should be called every 5 sec. The second should be called every 15´ and at best just after the first is ready. I have glib tree there which should be accessed (read only by the first function) and modified by the second one.
Do I need threads here? Or is there any better solution?

¿Fue útil?

Solución

g_timeout_add_seconds was added in glib-2.14, but g_timeout_add and g_timeout_add_full have been around since at least 2.0. They take milliseconds instead of seconds, so just multiply by 1000 and you should be fine.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top