Re: Instabilities with multi threaded application

On Fri, 2004-07-23 at 17:30, Tristan Van Berkom wrote:
> Tiago Cogumbreiro wrote:
> > Since Philip is using pthreads and gthreads use pthreads (in linux,
> > which i am assuming is his platform), wouldn't a simple gthreads_init,
> > suffice? 
> g_thread_init() will not create the gdk_threads_mutex.
> > Also, if only one thread changes the gui is the
> > gdk_threads_{enter,leave} needed surrounding main_loop?
> No (this is IMO recommendable that you dedicate on thread to that).
> > Are g_{idle,timeout}_add add thread safe? Can i call them from another
> > problems with no problems whatsoever? I'm am routing all my gui related
> > tasks to these functions and therefore skiping the gdk lock, is this an
> > acceptable procedure?
>  From what I understand, you can use event sources (GSource) in multiple
> threads provided that both threads run a GMainLoop and that both threads
> have thier own GMainContext.
> By the looks of the source, you cant use the convenience functions
> provided for timeouts and io watches etc, you would have to do something
> like this:
> thread() {
>    GMainContext *context  = g_main_context_new();
>    GMainLoop    *mainloop = g_main_loop_new(context, FALSE);
>    GSource      *source   = g_timeout_source_new(interval);
>    g_source_set_priority(source, priority);
>    g_source_set_callback(source, timeout_func);
>    g_source_attatch(source, context);
>    g_main_loop_run(mainloop);
> }
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.

> If you havent read this then you should:
> If you want to route information to your gui thread you'll have to use
> some means of IPC, you should read this thread in its entirety:
> There are a few ideas tossed around in this thread on the topic.
> [...]
> > I'm assuming this function came from somewhere else and had the name
> > g_strtokenize, it should be g_strsplit_set. Should i fill a bug report
> > about this?
> Why not, I guess it wont change untill someone changes it ;-)
Well, I've just done it, including the patch to fix it :)

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