What function is responsible for creating the global GMainContext?

I was looking into the documentation of GMainContext API. I can call g_main_context_default() to get the global default main context without having to create it first in my program. I can also create a GMainLoop using the global default main context as follow:

GMainLoop *loop = g_main_loop_new(NULL, FALSE);

The global default main context seems to be created implicitly at some point in a program. I can’t seem to find anywhere in the The Main Event Loop doc or the MainContext API that specify at what point in a program the global GMainContext is created and by what what function?

It is created by g_main_context_default() the first time the function is called in the program, and then it is stored in a static variable within that function for the rest of the program’s lifetime. Most other functions that accept NULL for a context will implictly call g_main_context_default() in that case, such as with g_main_loop_new(NULL, FALSE).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.