Re: Objects creation from within multiple threads

On Tue, 2007-08-28 at 14:10 +0200, David Nečas (Yeti) wrote:

> On Mon, Aug 27, 2007 at 05:21:26PM +0200, Vivien Malerba wrote:
> > I've got sereval threads from which I'm trying to create objects
> > (using g_object_new()) at the "same time", and I get strange errors
> > (most of the time it works correctly though).
> > 
> > A quick gdb session seems to show that when a problem occurs, all the
> > threads creating objects are in g_type_class_ref() in gtype.c which is
> > called from g_object_new().
> > 
> > For example error messages are:
> > ...invalidly modified type `XXX'
> > g_object_new_valist: object class `XXX' has no property named `YYY'
> > 
> > I cant' find any information about if GLib does not support creating
> > objects from different threads ate the same time. Can anyone help me?
> Since no one else replied... at least this: It should work.
> If it does not work and you think there's no error on your
> side, report it to bugzilla -- with some minimal example to
> reproduce it.  I don't understand these parts of code
> enough to tell whether the locking is correct (namely the
> temporary unlocking to reference the parent).

In general, creating objects of the same type at the same time from
multiple threads should work fine with any recent GLib, once all the
type stuff has been set up properly.

However, there still seem to be bits of the GType code which aren't
entirely thread-safe (class registration in particular), so you might
run into trouble if you try to create the first object of a certain type
at the same time from two different threads.  You should be able to work
around this by doing g_type_class_ref() for the affected types from a
single thread context, such as at the beginning of your application.

Bugs you might find interesting in this context: (Class initialization
isn't thread safe) (_get_type() functions
aren't thread-safe)


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