[Insight-developers] LightObject race condition fix

Peter Cech pcech at vision.ee.ethz.ch
Wed Jul 11 18:31:01 EDT 2007


On Wed, Jul 11, 2007 at 11:02:16 -0400, Karthik Krishnan wrote:
> 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..

It's past midnight here, so I'll refrain from trying to post any
solutions, but there is something relevant here:

http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30225804.aspx

Enjoy!

Peter


More information about the Insight-developers mailing list