Re: Atomic Reference Counts in GObject



Is there a concrete example of object resurrection somewhere, perhaps
in the GTK+ code itself?
I don't see why someone who might need the object wouldn't just keep
it alive by holding a reference to it instead of going to the trouble
of digging it out of the grave after it's already been dismembered...
My specific problem is the following.  I have a list of weak_refs,
which are weak because the thread using the list has no influence on
the object's life span -- it just needs to perform an action on the
objects that currently exist.  Hence, when an object is unref'ed, the
weak_ref will be removed from the list by the notifier.
Now, unfortunately, the dispose method begins to dismantle the
object... I can still pick it up in the other thread because it's
ref-count is 1, but the object is/may be incoherent.  Then, somewhere
near the end of 'disposing' of the victim, the ref-count is suddenly
set to 0 (see g_object_real_dispose)... now the weak notifiers are
called -- I can't resurrect the object in the weak notifiers because
the ref-count is 0.  This seems strange.  Why not?  It's still in the
same bad shape it was in before, and who else is going to notice that
the object is being disposed of if not the weak-notifiers?
Then, it gets worse: the ref-count is suddenly raised again.  Granted,
the weak notifiers have been called so I can hardly expect the object
to be coherent anymore, but if I am lucky, I can still get a reference
to the object (through the weak_refs, if I am devious and keep them
around after notification) and prevent it from being finalized.  At
this point we call in Dr. Frankenstein to bring it back to life...
Perhaps I am missing something and perhaps it's really obvious, but I
just do not see it.  My thinking is that the weak-notifiers should
probably be called just before the object-dispose method so that I
would know not to try to use the object anymore.  For example:
In g_object_last_unref:
1) call weak notifiers
2) if nobody has saved the object, call dispose (perhaps with
ref-count 1 because the weak-ref holders have been warned, allowing
for further life-saving measures somewhere -- in the dispose method
itself, I presume)
3) if still nobody has any partial remains, call finalize to make sure
the beast is really dead

Of course, I'm sure one of you could tell me why I'm wrong and I look
forward to your explanation!

Jonas



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