Re: Main loop revision



[ I just noticed Sebastian sent his mail separately to the mail 
  and the list, so I'm resending this to the list so everbody
  can see my response. ]

Sebastian Wilhelmi <wilhelmi@ira.uka.de> writes:

> Hi Owen,
> 
> > I've put up a proposal for a revision of the GLib main loop at:
> > 
> >  http://www.gtk.org/~otaylor/gtk/2.0/main-loop.html

> Very nice writeup. It looks quite nice. As I didn't see the
> implementation, I cannot say, whether the following will work (I
> would really like it to work): Is it possible to add a fd to
> different GMainContexts, such that I could have one Context with all
> my fds (think ORBit connections) and another Context with all my fds
> and additionally some other stuff (think X11 connection). Now I can
> either run the first Context (not dispatching X11 events, but only
> CORBA "events") and I could run the other Context for dipatching
> both event-types?  That would be great (And it seems, I can do it,
> this is just to make sure).

You can't add a single source to multiple contexts - that would
be quite hard to implement - but you can create multiple sources
that watch the same file descriptor. 

That doesn't go any deeper than the fact that you can call poll() on
the same file descriptor from multiple threads. Of course, then you
have to be careful that you guard against race conditions. You need to
use non-blocking reads everwhere since another thread may have read
the waiting data between the point where a file descriptor is marked
up as ready to read and the point where you actually try and
read the data.
 
> >  - If g_main_run() is called from a different thread than
> >    the thread for the main loop, then instead of failing
> >    it waits for g_main_quit() by a mechanism such as
> >    a semaphore
> 
> Can you still do 
> 
> while (g_main_pending(...)) g_main_iteration(...); 
> 
> in more than one tread or are you expected to use g_main_run?

[ First, doing:

 while (g_main_pending())
   g_main_iteration (FALSE)

 is just unnecessary overhead. Better to do just do:

 while (g_main_iteration (FALSE)) /* Nothing */; ]

You basically are not currently allowed to call g_main_iteration()
from more than one thread. (Although it might work in the special
circumstance where one thread was blocking in during dispatching of a
callback, and while that happened, another thead called
g_main_iteration())

Trying to make this work is very hard, since you have to make the main
loop recursive from every point you release the lock. And in many of
those places, what should work is not even clear.

So, I don't think I'm going to be able to relax the restriction
that each main context can only be iterated/run from a single thread.
If this is a crippling restriction, I can try and figure out
how that would work. It's not easy, though.

Regards,
                                        Owen





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