[Insight-developers] Re: LightObject race condition fix

Peter Cech pcech at vision.ee.ethz.ch
Tue Aug 7 06:28:55 EDT 2007


On Tue, Aug 07, 2007 at 01:35:37 -0500, Steve M. Robbins wrote:
> On Mon, Aug 06, 2007 at 05:03:45PM -0400, Simon Warfield wrote:
> 
> > I think the thread-safeness of these operations should be enforced or at 
> > least encouraged by some kind of API that makes it easy to do the right 
> > thing.
> 
> That's surely desirable, though I'm not smart or imaginative enough to
> see how an API could *enforce* safety: it's easy to call UnRegister()
> more times than Register(), even within a single thread.

It is doable if you do not allow to obtain raw pointer to LightObject.
If the only way of constructing the object is call to New() that returns
smart pointer and smart pointer does have any API to expose the raw
pointer, you can ensure* that per every raw pointer there is a
corresponding reference count.

[*] At least in reasonable written programs. There is always a
possibility to avoid the mechanism, e.g. memcpy the smart pointer.

Regards,
Peter


More information about the Insight-developers mailing list