[glib] Check for "our" threads in some places



commit 3fe3fdd75abb313fc43b58ebd4a71dcfe8bab32f
Author: Ryan Lortie <desrt desrt ca>
Date:   Sat Oct 15 09:48:42 2011 -0400

    Check for "our" threads in some places
    
    Don't allow g_thread_join() to be called on or g_thread_exit() to be
    called from within threads that were not created by GLib.  Document
    this.

 glib/gthread.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/glib/gthread.c b/glib/gthread.c
index 66939f5..1d7335b 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -849,14 +849,21 @@ g_thread_new_internal (const gchar   *name,
  * Calling <literal>g_thread_exit (retval)</literal> is equivalent to
  * returning @retval from the function @func, as given to g_thread_new().
  *
- * <note><para>Never call g_thread_exit() from within a thread of a
- * #GThreadPool, as that will mess up the bookkeeping and lead to funny
- * and unwanted results.</para></note>
+ * <note><para>
+ *   You must only call g_thread_exit() from a thread that you created
+ *   yourself with g_thread_new() or related APIs.  You must not call
+ *   this function from a thread created with another threading library
+ *   or or from within a #GThreadPool.
+ * </para></note>
  */
 void
 g_thread_exit (gpointer retval)
 {
   GRealThread* real = (GRealThread*) g_thread_self ();
+
+  if G_UNLIKELY (!real->ours)
+    g_error ("attempt to g_thread_exit() a thread not created by GLib");
+
   real->retval = retval;
 
   g_system_thread_exit ();
@@ -890,6 +897,7 @@ g_thread_join (GThread *thread)
   gpointer retval;
 
   g_return_val_if_fail (thread, NULL);
+  g_return_val_if_fail (real->ours, NULL);
 
   g_system_thread_wait (real);
 
@@ -910,6 +918,12 @@ g_thread_join (GThread *thread)
  * current thread. Note that this function does not increase
  * the reference count of the returned object.
  *
+ * This function will return a #GThread even for threads that were not
+ * created by GLib (ie: those created by other threading APIs).  This
+ * may be useful for thread identification purposes (ie: comparisons)
+ * but you must not use GLib functions (such as g_thread_join()) on
+ * these threads.
+ *
  * Returns: the #GThread representing the current thread
  */
 GThread*



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