Re: Changes to the GLib main loop [ g_main_iterate() ]
- From: Owen Taylor <otaylor redhat com>
- To: Sebastian Wilhelmi <wilhelmi ira uka de>
- Cc: gtk-devel-list gnome org
- Subject: Re: Changes to the GLib main loop [ g_main_iterate() ]
- Date: 29 Jun 2001 11:33:02 -0400
Sebastian Wilhelmi <wilhelmi ira uka de> writes:
> > My other fear would be that people would write:
> >
> > while (i_dont_have_a_message)
> > g_main_context_iteration (context, TRUE);
> >
> > Which, in a non-owner thread is hideously expensive. Just like the
> > case of the g_main_context_run().
>
> I don't think it is that expensive. Per iteration it costs one
> g_cond_broadcast in the owning thread, one context switch, and then
> the thread falls asleep again. Given that this happens only when a
> new event arives, it isn't that bad.
Just for the record:
On one system, the rough timing was (did it a week or so ago,
so from memory):
- Time for a context switch 2us, so the time to signal a thread
and let it go back to sleep, around 5us
- Time for iterations, including poll(), 10us
But remember that when dispatching a batch of pending events,
the poll() is skipped, so the main loop iteration is considerably
faster. [ No timing at hand ]
Also, if you have more than one thread waiting in that fashion,
they all wake up.
So, yes, I would consider this an expensive thing to do.
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]