Re: main loop & main context difference (follow up plz ?)



IIRC, you didn't get a reply for this one,
        I can lay down the part that I know.
(in the hope that this thread continues
and I learn something).

a main loop; is exactly what it sounds like.
its something like a:

while (1) {
        // main loop.
}

a main loop is responsible for keeping
track of "sources" and executing "sources"
i.e. 

int g_timeout_add();

returns a "source" (int) that will be added
to a list and when the "main loop" finds it 
apropriate; it will execute the "source"
(in this case ... calling your callback
and removing the "source" from the list
if your callback returns FALSE).


As I understand it; you can add sources
to your main loop only if you are in
the thread that your mainloop will run
(unless maybe using (gdk_threads_enter/leave ?)


I have no idea what a "context" is But; if
it didn't exist;   I would probably use the word
"context" instead of "tread" in the above paragraph.

What I think is shaky and possibly dangerous to 
the API (seeing as AFAIK nobody seems
to understand it as a "whole") is this:

when adding a "source" to the main loop
(possibly with g_io_add_watch() or
whatever) where is the argument "GMainLoop" ?

take for example the following code draft


void main() {

        GMainLoop loop1 = g_mainloop_new(...);
        GMainLoop loop2 = g_mainloop_new(...);

        g_timeout_add(args, callback, /*absence of arg GMainLoop*/);


        g_mainloop_run(loop1);
}

will `callback' ever get executed ???

why can I run different main loops (->threads?) in one context (really?
can I?) but not one context in different threads?

we know that its possible to have nested mainloops
where one mainloop runs inside a single iteration
of the "parent" mainloop. You can't run two main
loops concurently in the same thread.

I have to assume (since I havn't read the source yet)
that a "context" is some sort of "state machine"
associated with a "tread"; possibly even referenced
by "getpid()" (on the linux implementation at least).

There is definitly some assumtions made in the
core of gtk as to "how will the user aply this
api"; although this is still unclear to me.

While this might seem a little unsound to
to the few like me; who are interested in
how a function like "fopen()" works and
the relation to "stream->_fileno" and then
the coresponing "struct file_operations"
down to the machine OP code that talks to
your IDE controller; ----- it might not 
seem "unsound" at all to someone using
the library for practical day-to-day
use; provided he's equiped with 
easy-to-understand well-written
documentation. (not to mention a
tool as automagical as "glade"...).



Well; I think I've went sufficiently 
overboard today; which was alot of fun
and I hope I didn't get on anyone's 
nerves ;-)

I now have to get down to some actual "work"

Cheers all!,
                -Tristan


Axel Bock wrote:

Hi all,

perhaps I'm dumb, but I dont care anymore. :-)
But I really dont get it:

        what is the difference between main loops & main contexts????

I mean, a loop runs in a context, okay, but sources are attached to ...
what? the context? and the main context loops??? and when I set a new
loop with g_main_loop_new(g_main_context_new(), FALSE), do the sources
grab this when I attach them?

why can I run different main loops (->threads?) in one context (really?
can I?) but not one context in different threads?

can anyone help out, please ... I already found some article about
changes from glib-1.2 to glib-2.0, but (did I mentioned I feel quite
stupid right now? :-) I think there are some important connections
missing (means: I dont get it :-))

thanks in advance and greetings,

                axel.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



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