Re: Instabilities with multi threaded application



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);
}

If you havent read this then you should:
   http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html

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:
   http://mail.gnome.org/archives/gtk-list/2004-July/msg00107.html

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 ;-)

Cheers,
                               -Tristan





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