Re: Instabilities with multi threaded application

Tiago Cogumbreiro wrote:
Ouch, i was just doing this in the other thread:

MyGObject *self = MY_OBJECT(data);
/* push current state to queue */
g_async_queue_push(self->queue, GINT_TO_POINTER(new_state);
/* now start a g_idle call */
g_idle_add (on_event, data);

But, strangely enough, it works like a charm. I'll read the main event
loop more throughly.

    Hmmm, but you are not running a mainloop in your thread are you,
in which case your `on_event' function is getting called in your
parent thread, it looks neat and all, but I have a feeling that its
unsafe to modify a GMainContext from another thread, there is probably
a race condition in your code where both threads access the main
context at the same time and produce that age old "unpredictable behaviour".

In the thread I pointed out in the previous mail, we discuss implementing
an event source which pops elements off of a GAsyncQueue, where the thread
that pushes onto the queue, calls g_main_context_wakeup() on the context
of the recieving thread.


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