GTypeModule and threads

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

GTypeModule and threads

Jannis Pohlmann-3
Hey,

is GTypeModule supposed to be thread-safe? I'm currently working on an
application with a plugin interface based on GTypeModule. The
application itself runs several threads which create objects of the
types exported by the GTypeModule.

Now, if I wait long enough and give the application enough to work on,
I always end up with the same result: the application crashes with the
following error:

GLib-GObject:ERROR:gtype.c:1135:type_data_ref_Wm: assertion failed:
(node->data->common.ref_count > 0)

I suppose this is a race condition where one thread unref's the last
instance of a type exported by the GTypeModule and another tries to
create a new instance at about the same time. Please correct me if I'm
wrong here.

Is this supposed to work or am I doing something entirely
unsupported? ;)

_______________________________________________
gtk-devel-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-devel-list

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GTypeModule and threads

Andrew Cowie
On Mon, 2009-06-15 at 19:17 +0200, Jannis Pohlmann wrote:
> is GTypeModule supposed to be thread-safe?

I don't think so.

[The only thing I know about this topic comes from comments 3-5 on
http://bugzilla.gnome.org/show_bug.cgi?id=534573#c3 but I certainly
trust Matthias to know what he's talking about]

AfC
Sydney


_______________________________________________
gtk-devel-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-devel-list

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GTypeModule and threads

Jannis Pohlmann-3
In reply to this post by Jannis Pohlmann-3
On Mon, 15 Jun 2009 19:17:54 +0200
Jannis Pohlmann <[hidden email]> wrote:

> Hey,
>
> is GTypeModule supposed to be thread-safe? I'm currently working on an
> application with a plugin interface based on GTypeModule. The
> application itself runs several threads which create objects of the
> types exported by the GTypeModule.
>
> Now, if I wait long enough and give the application enough to work on,
> I always end up with the same result: the application crashes with the
> following error:
>
> GLib-GObject:ERROR:gtype.c:1135:type_data_ref_Wm: assertion failed:
> (node->data->common.ref_count > 0)
>
> I suppose this is a race condition where one thread unref's the last
> instance of a type exported by the GTypeModule and another tries to
> create a new instance at about the same time. Please correct me if I'm
> wrong here.
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?

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.

Cheers,
Jannis

_______________________________________________
gtk-devel-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-devel-list

signature.asc (204 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GTypeModule and threads

Tim-Philipp Müller
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
code.

 Cheers
  -Tim

[1] http://bugzilla.gnome.org/show_bug.cgi?id=166020#c61

_______________________________________________
gtk-devel-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-devel-list