Re: glib main loop concept

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

 



Hi,

thanks for the hints, however, some more questions below..

Donny Viszneki wrote:
> I'm a bit of a newb to this, so others should feel free to correct me.
> 
> On 10/2/07, Christian Buennig <masala@xxxxxx> 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.

Ok. This is not a suggestion to change the GLib API, but to make sure I
understood it right: Semantically a function name like:

g_main_loop_get_ref(..)

would better describe what this function does? I think so because I
guess calling g_main_loop_new(..) within the same thread multiple times
 technically always gives a reference to the same main loop ..

> 
>> * 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.

Well, the API forces me to set something for this parameter when I
create a new main loop with:

g_main_loop_new(GMainContext *context, gboolean is_running)

As I understand the GLib reference, it does not matter how to set
'is_running' if I call g_main_loop_run(..) later. However, I just wonder
why there is this parameter if it does not make sense for API users.

> 
>> 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@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux