Re: g_main_loop and g_async_queue

On Mon, 5 Jan 2009 09:56:24 +0000
Chris Vine <chris cvine freeserve co uk> wrote:

> On Mon, 5 Jan 2009 07:45:02 -0200
> Cris <ternaryd gmail com> wrote:
> > Is there a way to have the main loop react upon a message becoming
> > available from a different thread on an asynchronous queue?
> > 
> > I'm having a main loop which is somewhat time critical, and a thread
> > which is dedicated to tasks which can take longer and have often a
> > lesser priority. I chose to use threads over forks because complex
> > data sets need to be exchanged between the two. Is there some other
> > method I could use instead of asynchronous queues?
> g_idle_add(), or g_idle_add_full(), are intended for use for message
> passing to the event loop of the main program thread.  They are thread
> safe.

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.



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