Re: g_main_loop and g_async_queue

On Mon, 5 Jan 2009 09:01:17 -0200
Cris <ternaryd gmail com> wrote:
> My problem is with the communication coming from the secondary thread,
> signaling the primary that it can get a result. How could this be done
> using the idle function? Also, if the idle function is only called if
> the normal (time critical events) processing is idle, in this case, it
> would be called probably almost never, as it can get quite busy.
> There is a solution to it, using standard unix pipes as I would do
> using forked processes rather than threads (but with those I would
> have to encode and decode complex data structures while with threads
> I can get away using mutexes). With g_io_add_watch I can have the
> main loop trigger my function whenever the secondary thread has
> finished a job and sends some random byte. I was wondering however,
> if there is a more glib-style solution to it.

g_idle_add_full() enables you to set any priority in the event loop you
like.  On Unix systems it does exactly what you describe - it uses a
pipe on which the main loop has registered a handler.  That (amongst
other reasons) is why it is thread safe.

If you choose G_PRIORITY_HIGH it will execute the callback even ahead
of your GDK drawing functions.  I doubt that that is desirable though.

If this kind of event passing doesn't suit your program you will need
to redesign it as it will certainly not work with your proposed
fork()ing.  Incidentally, each thread can have its own event loop,
which may reduce the need for you to pass events to the main loop - but
at some stage you are going to have to announce your results to it.


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