What is advantage of using GMainLoop from glib.h rather than "while(true);" in C++ linux?
Asked Answered
D

1

5

I have come across a code where they needed an infinite loop & they used

    GMainLoop *mainloop = NULL;

    mainloop = g_main_loop_new (NULL, FALSE);
    g_main_loop_run (mainloop);

I have doubt why don't they use while(true); for same purpose. What does GMainLoop internally do, Ain't it will be same internally. How does GMainLoop enhances the performance.

Dike answered 10/12, 2014 at 8:32 Comment(0)
S
10

g_main_loop means the main event loop in glib. It is not just an infinite loop; it polls event sources, queues events it gets from them, and invokes event handlers. It also doesn't do that busily; that is to say, it'll not go to 100% CPU usage when nothing is happening (unless an event source is broken).

There's a description of it in the glib documentation.

Sneaky answered 10/12, 2014 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.