Re: g_thread_init question



Alan M. Evans wrote:
Hello all!

The docs on developer.gnome.org state that g_thread_init() will abort if
called twice and suggest the following construct to avoid multiple
calls:

  if (!g_thread_supported ()) g_thread_init (NULL);

Has nobody noticed that there's a race condition there?

If I make a class that internally uses threads and mutexes, how do I
protect myself against another class (not necessarily mine) created in
another thread (not necessarily under my control) also calling
g_thread_init() because it is also internally using gthread?

    That sounds conceptualy broken, if I instantiate a GObject that
is a GtkWidget, the GtkWidgetClass initializer will not call gtk_init()
for me, so why should an object using the thread system have to call
g_thread_init () ?

Maybe it would be appropriate for the class initializer to do:

  if (!g_thread_supported ())
       g_critical ("You must initialize the thread subsystem "
                   "to use MyObjectClass");


Cheers,
                        -Tristan



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