Thread-safety issue in GObjects
- From: Aleksander Morgado <gtk-list aleksander es>
- To: gtk-list gnome org
- Subject: Thread-safety issue in GObjects
- Date: Thu, 21 May 2009 14:26:12 +0200
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]