[Openib-windows] RE: Reference count as a solution to the pro blem of an object lif e time

Fabian Tillier ftillier at silverstorm.com
Wed Sep 21 14:01:17 PDT 2005


On 9/21/05, Tzachi Dar <tzachid at mellanox.co.il> wrote:
>
>
> Hi Fab,
> It seems that I still don't get your model (sorry for that)

No worries - I'm more than happy to explain it, as it is rather important.

> Just a small question that might help me understand it. Why do you call your
> model a reference counting model. If I understand correctly you only take
> the reference once, and when you get the callback you remove it.

A reference counting model only requires that an object not be
destroyed while a reference is outstanding.  There is no requirement
that the reference count use values other than zero and one.

> Is their any chance that the reference will ever reach 5 for example? (or 10
> or 20). It still seems to me as an exist don't exist one.

The callbacks don't increment/decrement an external reference count
because they don't need to - the mere existance of the object implies
the existence a reference on the callback context.  The object's
internal reference count will go up to prevent its destruction, which
is needed to make sure that the callback has something to unwind to.

Note that an object's implementation could use something other than a
reference count.  For example, a flag to indicate a callback is in
progress could work for a simple object where only one callback can
occur at a time.

The important part of the reference count is that it not reach zero
prematurely.  It doesn't matter how high it gets, as long as it's not
zero prematurely.

The user's reference count could go up and down for other reasons
internal to the user's implementation, and that has no effect on the
behavior.  As long as there's a reference on behalf of every created
object, and that reference is only released from the object's destroy
callback, everything is guaranteed to work properly.

- Fab



More information about the ofw mailing list