Re: Glib main loop update



Quoting Owen Taylor (otaylor@redhat.com):
> 
> Raph Levien <raph@acm.org> writes:
> 
> > Looks pretty good to me, although I can't say I understand every subtle
> > detail. Certainly, abstracting over the differences between Unix and
> > Win32 is a noble goal.
> > 
> > One question I had - when programming with threads, is there a way to
> > make a condition variable "wake up" the select in the mainloop? I
> > thought of using a pipe for this, but that seems less than ideal.
> 
> GTK+ currently uses a pipe for this. (See gdk_threads_wake()).
> As far as I know, this is the only way of handling it, since
> select() and poll() are separate from the threading system.
> 
> With GTK+'s main loop now, because it does this wakeup, if,
> in a thread, you want to execute some code in the main loop,
> you can do this with:
> 
>  gdk_threads_enter();
>  gdk_idle_add (func_to_execute, NULL);
>  gdk_theads_leave();

Just a thought here...  Generally speaking, there are two ways to
to return from select() before a timeout.  The first is when a fd
is ready, and the other is to deliver a signal which interrupts
select().  Of course, this is harder to get right, less portable,
and probably less efficient than using a pipe in the first place.
I think pipes are probably best.

-josh



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