Re: g_thread_init question

Alan M. Evans wrote:
The comparison lacks parity, in my opinion. It seems unlikely to me that
a class which uses GtkWidget would be used in a non-GTK+ program.
("Class" in the C++ sense, not the GObject sense.)

I am tempted to argue that "class" in the c++ sence *is* the same
as a "class" in the GObject sence; but that is a little off-topic :)

On the other hand, It seems completely feasable that a class that uses
GLib types and threads might be used in an application which has no
knowledge of GLib. In fact, that's exactly what I'm doing.

In other words, a shared object that uses GLib might not expose GLib,
but how would a shared object that uses GTK+ not expose that?

    The race condition is present only if you make it possible that
you call g_thread_init () from two seperate threads, to be blunt;
its your responsability to make sure that doesn't happen.

Lets take another few examples, firstly; you cannot use any
GObject derivitive unless the typesystem is initialized; so
g_type_init() must be called first (whether it is called by
gtk_init () or by gdk_rgb_init () or whatever).

Same goes for gdk objects, the gdk_rgb_init() function will
initialize subsystems that must be present first.

I think that a more appropriate example would be GStreamer,
GStreamer needs to have threads initialized to function;
So GStreamer demands that you call gst_init () /before/
using GStreamer objects.

So lets say that you are writing an application that uses
GStreamer, GTK+ & your shared object, in your main () you
will call each of the following:

void main () {
    gtk_init (); // <-- calls g_threads_init ()
    gst_init (); // <-- calls g_threads_init ()
    my_customlib_init (); // your shared object library init point
    // that will also call g_threads_init ()

Since all library entry points check g_thread_supported (), there
is no crash, also since it is part of the apps initialization
proceedure; there is no danger of a race condition.


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