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.
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.