[Insight-developers] LightObject race condition fix

Karthik Krishnan karthik.krishnan at kitware.com
Wed Jul 11 11:02:16 EDT 2007


On 7/11/07, Gaëtan Lehmann <gaetan.lehmann at jouy.inra.fr> wrote:
>
>
> Le 11 juil. 07 à 15:33, Karthik Krishnan a écrit :
>
> > However I agree with Steve/Luis that access of the resource
> > m_ReferenceCount be thread safe. One solution would be to use a
> > scoped lock (unlocking is implemented in its destructor, so it
> > automatically does that when it goes out of scope).
> >
> > The code would look like
> >
> > UnRegister()
> > {
> >   ScopedLock lock( m_ReferenceCountLock )
> >   m_ReferenceCount--;
> >   if ( m_ReferenceCount <= 0) { delete this;  }
> > }
>
> Please correct if I'm wrong, but the mutex lock will be destroyed by
> the delete call before the destruction of the ScopedLock object,


You're right.. How silly of me :) I'd suggest leaving it as is..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.itk.org/mailman/private/insight-developers/attachments/20070711/e0c376f5/attachment.htm


More information about the Insight-developers mailing list