Will GTK + timeout calls be called in strict order?

When I add many different timeouts (with each intervall==0) to a thread that is not , the main thread (where it gtk_main()is) ...

g_timeout_add(0, func, NULL);

... then different callbacks func()will occur in the same order that I called appropriate g_timeout_add()'?


The reason I'm asking is because GTK # uses internal timeouts for implementation Application.Invoke()(see Application.cs and Timeout.cs ).


EDIT: Regarding glib files

+3
source share
2 answers

Internally, g_timeout_add calls g_hook_insert_sorted . If g_timeout_add_full is used, priority determines the order, otherwise a hook is added at the end of the list. The hooks are executed in order, so when only g_timeout_add is used, the answer is yes.

Unfortunately, there is no explicit guarantee, and for me it looks like an implementation detail that may change in the future.

+4
source

How to enforce call order by explicitly storing your callbacks in a list, and then using one g_timeout_add () to call a function that iterates through this list?

static gboolean
call_in_order (GList* callbacks)
{
  for (; callbacks != NULL; callbacks = callbacks->next)
    {
      g_assert (callbacks->data != NULL);
      GSourceFunc callback = (GSourceFunc)(callbacks->data);

      callback(NULL);
    }
}


...

 GList *callbacks = NULL;
 callbacks = g_list_append(callbacks, func1);
 callbacks = g_list_append(callbacks, func2);
 callbacks = g_list_append(callbacks, func3);
 callbacks = g_list_append(callbacks, func4);

 g_timeout_add(0, (GSourceFunc)call_in_order, callbacks);
0
source

Source: https://habr.com/ru/post/1731680/


All Articles