When I add many different timeouts (with each intervall==0
) in a thread, which is not the main thread (where gtk_main()
resides)...
g_timeout_add(0, func, NULL);
... will then the different func()
callbacks occur in the same order I called the corresponding g_timeout_add()
's?
The reason I'm asking is because GTK# is using internally timeouts to implement Application.Invoke()
(see Application.cs and Timeout.cs).
EDIT: The concerning glib files are
Internally, g_timeout_add calls g_hook_insert_sorted. If g_timeout_add_full is used, the priority determines the ordering, otherwise the hook is added at the end of the list. Hooks are executed in order, so when only g_timeout_add is used, the answer is yes.
Unfortunately, there is not no explicit guarantee, and to me, it looks like an implementation detail which might change in the future.
How about enforcing the order of the calls by storing your callbacks explicitly in a list, then using a single g_timeout_add() to call a function that iterates over that 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With