Thread-safety issue in GObjects

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

 



Hi all,

Small question about GObject management in multi-threaded applications.

I've got a GObject with a "gpointer priv" in the GObject struct, which is just a pointer to the private info of the object. That pointer is set to NULL when g_object_unref() is called, after the private data has been deallocated. What I see is that thread 1 calls g_object_unref() and, it seems that meanwhile another thread 2 gets a new reference of it with g_object_ref().

GDB shows the following after a segfault:
(gdb) p *self
$2 = {parent = {g_type_instance = {g_class = 0x99efd30}, ref_count = 1, qdata = 0x0}, priv = 0x0}

What I understand from this is that g_object_unref() was called, as priv is NULL, and still then a reference to the object is available.

The specific question is, what happens when one thread calls g_object_unref() and just while it's being executed the unref() another one calls g_object_ref()? Should my application try to avoid this situation making all the ref()/unref() operations thread-safe at application level?

Cheers and thanks,
-Aleksander
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux