A Sex, 2004-02-27 �s 13:22, Christian Robottom Reis escreveu:
> On Mon, Feb 23, 2004 at 01:14:36PM +0000, Graham Carlyle wrote:
> > --
> > import pygtk
> > pygtk.require("2.0")
> > import gc
> > import gobject
> > import gtk
> >
> > class Foo:
> > pass
> >
> > list_store = gtk.ListStore(gobject.TYPE_PYOBJECT)
> > list_store.prepend((Foo(),))
> > gtk.threads_init()
> > list_store = None
> > gc.collect()
> > --
> > results in the message:
> > "Fatal Python error: PyThreadState_Get: no current thread
> > Aborted"
>
> I'm not sure you're supposed to call threads_init() this late in life.
> Now, never having used threads before, I'm going to ask Johan and
> Gustavo to tell us what they think of this. I'm not sure about this:
>
> > static void
> > pyobject_free(gpointer boxed)
> > {
> > PyObject *object = boxed;
> >
> > + pyg_block_threads();
> > Py_DECREF(object);
> > + pyg_unblock_threads();
> > }
>
> Isn't Py_DECREF supposed to be an atomic operation?
Nope. This issue is not mentioned anywhere I could find. However,
looking at source (see below), it doesn't look atomic to me...
But the real issue is that Py_DECREF possibly triggers
g_object_unref(), and the latter is not (yet) thread-safe.
However, this patch is not a good idea at all, as it uses a couple of
very expensive mutex lock/unlock operations for each object freed. We
can avoid this, and following the gtk+ approach, if the programmer is
responsible for not sharing a single GObject between two threads. Or if
the programmer wishes to do so, he should use explicit locking around
operations on such objects.
That's my opininion anyway...
#define Py_DECREF(op) \
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
--(op)->ob_refcnt != 0) \
_Py_CHECK_REFCNT(op) \
else \
_Py_Dealloc((PyObject *)(op))
>
> Take care,
> --
> Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 261 2331
> _______________________________________________
> pygtk mailing list [EMAIL PROTECTED]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
--
Gustavo Jo�o Alves Marques Carneiro
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
The universe is always one step beyond logic.
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/