Re: Changes to the GLib main loop [ GMainLoop ]



Hi Owen,

> > > Also, using g_main_loop_run() to wait for, say, a modal dialog,
> > > in a second thread has become _much_ less efficient since you
> > > are waking up the second thread via g_cond_broadcast() on
> > > _every_ iteration. In face, I'd consider this to be an
> > > unacceptable performance hit. The reason why each GMainLoop
> > > currently has a separate condition variable is to avoid this.
> >
> > Ok, but that could be optimized away by also telling
> > g_main_context_iterate, whether it was called from g_main_loop_run or
> > not only signalling other threads, when it was not run from
> > g_main_loop_run. For calls not done from g_main_loop_run it would
> > still need to be called, because of the scenario outlined above (the
> > thread A and B thingy)
> 
> This doesn't work because the thread needs to be woken up to check for
> loop->is_running, even before the main loop stops running its loop.
> 
> (Remember, what I want to be able to do here is use main loop to wait
> for a modal dialog being closed, whether or not the dialog is being
> shown from the main thread.)

Ah, I see, but the solution to this is calling g_cond_broadcast in
g_main_loop_quit. So I think the following is enough:

* Make g_main_context_iterate call g_cond_broadcast only when not called 
  from g_main_loop_run.
* Make g_main_loop_quit call g_cond_broadcast.

Does that sound like it should work.

> Basically, we need to wait on the condition:
> 
>  loop->is_running || loop->context->owner == NULL
> 
> Trying to do this without having a conditional variable for _this_
> condition is going to be really inefficient. I think we indeed
> need to have a separate (demand created) condition variable for each
> GMainLoop.

Yes, but having a condition variable for the loop does also mean, that the
context (in an iteration) would have to signal all loops for that context.
That sounds much more inefficient.

Bye,
Sebastian
-- 
Sebastian Wilhelmi
mailto:wilhelmi ira uka de
http://goethe.ira.uka.de/~wilhelmi




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