/* gcc -o test test.c `pkg-config --libs --cflags glib-2.0`  && ./test */

#include <glib.h>

static gboolean
timeout_func(gpointer data)
{
    guint64 counter = 0;
    while (counter < 5000)
        counter++;
    g_printerr("done\n");
    return TRUE;
}

static gboolean
lowprio_timeout_func(gpointer data)
{
    g_printerr("low priority\n");
    return TRUE;
}
static gboolean
call_when_running(gpointer data)
{
    gint timeout_id, lowprio_timeout_id;
    timeout_id = g_timeout_add_full(G_PRIORITY_HIGH_IDLE + 20, 0,
                                    timeout_func, NULL, NULL);

    lowprio_timeout_id = g_timeout_add_full(G_PRIORITY_LOW, 1,
                                            lowprio_timeout_func, NULL, NULL);
    return FALSE;
}

int 
main (int   argc,
      char *argv[])
{
    GMainLoop *main_loop;

    main_loop = g_main_loop_new (NULL, FALSE);

    g_idle_add(call_when_running, NULL);

    g_main_loop_run (main_loop);
    g_main_loop_unref (main_loop);

    return 0;
}
