Re: GTypeModule and threads

On Tue, 2009-06-16 at 11:52 +0200, Jannis Pohlmann wrote:

> I played with this a bit more and it seems it's not related to
> GTypeModule all. Even if I make the GModule resident and never unuse
> the GTypeModule, I still end up with this error. So the question is, is
> GType or at least g_object_new() thread-safe? Or if it's not, shouldn't
> it be?

For what it's worth, GStreamer uses GType/GObject in a heavily
multithreaded context fairly successfully, so it should generally work
just fine as long as you're aware of a few things:

 - you need to make sure your _get_type() functions are thread-safe
   (via g_once_init_enter/leave() or somesuch)

 - g_object_notify() and by extension g_object_set() are not
   thread-safe (yet) and bad things will happen if they are
   concurrently used on the same object+property. A fairly
   straight-forward patch for this issue is available in
   bugzilla [1], but is sadly still waiting for review.

 - you need to do locking internally in your object
   implementation as needed (e.g. for properties etc.)

(hope I didn't forget anything)

> Excerpt of the backtrace of the above error:
> #3  0xb7ec0f17 in g_assertion_message () 
> #4  0xb7ec14dd in g_assertion_message_expr ()
> #5  0xb7f6458f in g_type_class_ref ()
> #6  0xb7f49268 in g_object_newv ()
> #7  0xb7f497b1 in g_object_new_valist ()
> #8  0xb7f49920 in g_object_new ()
> Any help would be greatly appreciated. Seems like I can reduce the risk
> of this error to appear by protecting parts of my code with mutexes but
> that still isn't 100% safe and it looks to me like this might be a bug
> in GObject/GType.

This looks a lot like the infamous bug #64764, which was fixed quite
some time ago, however. What GLib version are you using? I think the fix
made it into 2.16. If this is in fact the same issue, you can work
around it by doing a g_type_class_ref(type) at the beginning of your



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