Re: GTK app misbehaving. (main thread blocking)



> The simplest would be something like this:
>
> gboolean
> status_msg (gchar *msgdup)
> {
>  .... update status bar ...
>   g_free(msgdup);
>   return FALSE; /* only call once */
> }
>
>
> work_thread_func ()
> {
>    ....
>    g_idle_add (status_msg, g_strdup_printf("current value = %u", 99);
>    ....
> }

Excellent. That fixed the whole problem.

Thanks a bunch.
--Alex

Tim Müller wrote:
On Saturday 24 April 2004 20:28, you wrote:


I know, and I tried. The problem is, of course, that things like status
bar push and pop fail when called from the work thread. (Now that I know
that GTK is not thread safe, that explains the erratic/unreliable
behavior that came from trying that.)

I wonder if I could simply force my work thread to emit signals which
cause the GTK thread to change the statusbar?

Perhaps not.


The simplest would be something like this:

gboolean
status_msg (gchar *msgdup)
{
 .... update status bar ...
  g_free(msgdup);
  return FALSE; /* only call once */
}


work_thread_func ()
{
   ....
   g_idle_add (status_msg, g_strdup_printf("current value = %u", 99);
   ....
}

GLib, in particular the GLib main loop stuff, is thread-safe, so when you do a simple g_idle_add() or g_timeout_add() from your work thread, the dispatch will actually be happening from the main context/thread. That's the easiest way to get stuff across to the main thread.

Cheers
-Tim




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