Re: glib main loop concept



I'm a bit of a newb to this, so others should feel free to correct me.

On 10/2/07, Christian Buennig <masala web de> wrote:
> Hi,
>
> I have a general question about the concepts of GLib main loops.
>
> I've read the GLib reference several times but still I don't get how
> main loops internally work. To be precisely, the following questions occur:
>
> * Do main loops exist per process or per thread?
>   If I start a main loop in one thread (A) and add an IO watch in
>   another thread (B), does this watch get added to the main loop of the
>   thread A or B ?

Technically per thread, but also per process. The purpose of the main
loop is so that events can be pushed into a queue and processed
sequentially as opposed to responding to asynchronous events in an
interrupted stack frame. The result is simpler coding because you
don't need to worry as much about thread-safety.

> * If there is only one main loop (regardless of per thread or per
>   process), why the function g_main_loop_new()?

You can use multiple threads each having their own GMainLoop. But many
applications don't need it. Obviously however, such applications can
become unresponsive if they come under heavy load.

> * What's the purpose of the parameter 'is_running' in
>   g_main_loop_new() ? When should I set it to TRUE and when to FALSE?

You should not set these values yourself. They are set by glib API
calls which enter and exit one or multiple iterations of the loop.

> Sorry for this basic questions .. if I am not the only one dealing with
> these questions, maybe the GLib reference could get extended with more
> details on main loops.

Yeah, "glib-The-Main-Event-Loop.html" is a strikingly opaque piece of
documentation.

> Cheers .. and thanks for some advise,
>
> Christian
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>


-- 
http://www.socsurveys.org/
http://blogger.socsurveys.org/
http://del.icio.us/hdon



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]