rfc about a threads warning



the following patch to Glib will cause a warning to be printed if a
thread (perl ithread) is spawned at any point after gperl_new_object has
been called. this is not necessarily going in or anything, its intention
is just to purpose such a thing. at the very least until we find a
workable solution to the refcount/cleanup/destroy problems introduced by
the CLONE calls.

the patch will allow you to do things so long as you ensure that all
threads are spawned before any gobjects are created. what are the
opinions on the matter, should we prevent it from happening?

-rm
? .enum_test.pl.swp
? Glib-1.030.tar.gz
? fntu.pl
? test_it.pl
? thread_ref.patch
? thread_warn.patch
Index: GObject.xs
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/GObject.xs,v
retrieving revision 1.24
diff -u -r1.24 GObject.xs
--- GObject.xs  21 Nov 2003 06:31:28 -0000      1.24
+++ GObject.xs  12 Jan 2004 02:11:50 -0000
@@ -66,6 +66,7 @@
 
 static GQuark wrapper_quark; /* this quark stores the object's wrapper sv */
 
+static gboolean gobject_created = FALSE;
 
 /* thread safety locks for the modifiables above */
 G_LOCK_DEFINE_STATIC (types_by_type);
@@ -505,6 +506,8 @@
        SV *obj;
        SV *sv;
 
+       gobject_created = TRUE;
+
        /* take the easy way out if we can */
        if (!object) {
 #ifdef NOISY
@@ -721,6 +724,16 @@
 =cut
 
 MODULE = Glib::Object  PACKAGE = Glib::Object  PREFIX = g_object_
+
+=for apidoc __hide__
+=cut
+void
+CLONE (class)
+    CODE:
+       if (gobject_created)
+               croak ("warning: if you use threads with Gtk2-Perl you must "
+                      "spawn all threads before creating any Gtk2-Perl "
+                      "objects.");
 
 =for object Glib::Object Bindings for GObject
 


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