Re: Clarification on Glib Thread-Safe Operation




Owen Taylor wrote:

On Thu, 2003-10-02 at 10:43, David Judkovics wrote:
My project makes extensive use of what I believe are glibs non thread
related functions and types.  The wording of the documentation
concerning glib thread safe operation has left me confused.

The documentation states glib must be compiled with the macro
'G_THREADS_ENABLED' defined for thread safe operation.

..."This macro is defined, if GLib was compiled with thread support.
This does not necessarily mean, that there is a thread implementation
available, but the infrastructure is in place and once you provide a
thread implementation to g_thread_init(), GLib will be multi-thread
safe. It isn't and cannot be, if G_THREADS_ENABLED is not defined."...

Not that all that G_THREAD_ENABLED being defined means is that
you didn't pass

--disable-threads

to GLib's configure. Thread support is the default.


Owen,

Thats the corollary to my question, I think. I have the default configuration for glib and 'G_THREADS_ENABLED' is not defined. If 'G_THREADS_ENABLED' is not defined does that mean '--disable-threads' was passed to configure? Or is the fact I'm using the default build mean this is a thread safe lib with or without 'G_THREADS_ENABLED' defined?


Later on the documentation for 'g_thread_init()' states,
..."Before you use a thread related function in GLib, you should
initialize the thread system. This is done by calling g_thread_init().
Most of the time you will only have to call g_thread_init(NULL)."...

To me thread safe operation and the use of glib thread related
functions are two distinct configuration issues.  The documentation
seems to mix them.
This is my confusion.

How do you think GLib achieves thread-safe operation? It uses the
glib thread related functions.

My project is a library that uses the 'g_slist_' calls extensively,
calls I believe that are not thread related.  My project library must
be thread safe.  The version of glib we are using does not have
'G_THREADS_ENABLED' defined.  Is my project library thread safe within
the context of its use of glib's 'g_slist_' calls?

Put another way,  is glibs 'g_slist_' calls thread safe without
'G_THREADS_ENABLED' defined?

If you disabled thread support when compiling GLib, you
cannot use it from a threaded application.

Regards,
					Owen








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