Re: Threads



Olexiy Avramchenko wrote:
Russell Shaw wrote:

Ok, in gtkmain.c:

void
gtk_main (void)
{
  ...
  if (g_main_loop_is_running (main_loops->data))
    {
      GDK_THREADS_LEAVE ();
      g_main_loop_run (loop);
      GDK_THREADS_ENTER ();
      gdk_flush ();
    }
  ...
}

So if g_main_loop_run() runs for the duration of the app, then there is nothing guarding gdk calls made by gtk callbacks. So, doesn't this mean that every gtk operation in a gtk callback that eventually calls a gdk function, should be
surrounded by gdk_threads_enter()/leave() ?


GTK register a gtk_main_do_event() function to be called on every event (see gdk_event_handler_set in "gtk/gtkmain.c").

Ok, i didn't look hard enough. It's buried way down in gtk_init() in the
parser init stuff.

> GDK locks the mutex
before gtk_main_do_event() call (see gdk_event_dispatch in "gdk/x11/gdk-events-x11.c"). Every gtk callback invoked from main loop will be automatically protected. You should protect only code in *timeout* and *idle* callbacks, because they run outside gdk event dispatching code.

Ok. Atleast i have an idea of how to track down threading bugs now.



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