g_object_weak_ref, g_object_add_weak_pointer: document non-thread-safety
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 6 Dec 2011 11:37:45 +0000 (11:37 +0000)
committerRyan Lortie <desrt@desrt.ca>
Mon, 2 Jan 2012 17:23:11 +0000 (12:23 -0500)
Transparent access to a weak pointer from the thread performing the
weak -> strong conversion is incompatible with thread-safety: that
thread will have to do something special. This is GNOME#548954.

https://bugzilla.gnome.org/show_bug.cgi?id=548954

gobject/gobject.c

index 874096e..a8d4f9e 100644 (file)
@@ -2462,6 +2462,10 @@ weak_refs_notify (gpointer data)
  * "weak references" because they allow you to safely hold a pointer
  * to an object without calling g_object_ref() (g_object_ref() adds a
  * strong reference, that is, forces the object to stay alive).
+ *
+ * Note that the weak references created by this method are not
+ * thread-safe: they cannot safely be used in one thread if the
+ * object's last g_object_unref() might happen in another thread.
  */
 void
 g_object_weak_ref (GObject    *object,
@@ -2546,6 +2550,11 @@ g_object_weak_unref (GObject    *object,
  * the pointer located at @weak_pointer_location is only valid during
  * the lifetime of @object. When the @object is finalized,
  * @weak_pointer will be set to %NULL.
+ *
+ * Note that as with g_object_weak_ref(), the weak references created by
+ * this method are not thread-safe: they cannot safely be used in one
+ * thread if the object's last g_object_unref() might happen in another
+ * thread.
  */
 void
 g_object_add_weak_pointer (GObject  *object,