Re: thread initialization



The g_thread_supported() call only returns TRUE if g_thread_init() has already been called, it returns FALSE until the first call to g_thread_init() in each thread. After that it returns TRUE. I am no expert with the glib threading code, but reading the docs it seems you need to call g_thread_init() once per thread you instantiate. So either just call 
g_thread_init(NULL);
gdk_threads_init(); 
once at the top of your thread. If you have to call the init code from a place where it may have been called before then use your IF statement but leave off the else part.
if(!g_thread_supported()) {
  g_thread_init(NULL);
  gdk_thread_init();
}
If g_thread_supported() returns TRUE there is no need to call g_thread_init() since it was already called before.

You seem to be trying to use g_thread_supported() to determine if your system supports threading. That is not what it is for. You have to determine that at compile time, not runtime. 

Peter Long

----- Original Message ----
From: "z pekar gmail com" <z pekar gmail com>
To: gtk-list gnome org
Sent: Friday, December 28, 2007 8:07:56 AM
Subject: thread initialization


I have following thread initialization routine:

    if (!g_thread_supported()) {
        g_thread_init(NULL);
        gdk_threads_init(); // Called to initialize internal mutex
"gdk_threads_mutex".
    } else {
        g_print("Error: g_thread not supported.\n");
        gtk_main_quit ();
    }

on the first call of the function that has that code everything works
ok, but on the second call - it enters the else statment and says
Error: g_thread not supported.
what is wrong?
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





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