Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2004 10:42:35 -0700 (PDT)
From:      Julian Elischer <julian@elischer.org>
To:        Doug Rabson <dfr@nlsystems.com>
Cc:        cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/sys/kern kern_proc.c
Message-ID:  <Pine.BSF.4.21.0406091042030.57882-100000@InterJet.elischer.org>
In-Reply-To: <1086798299.12306.3.camel@builder02.qubesoft.com>

next in thread | previous in thread | raw e-mail | index | archive | help


On Wed, 9 Jun 2004, Doug Rabson wrote:

> On Wed, 2004-06-09 at 10:33, Poul-Henning Kamp wrote:
> > In message <200406090929.i599T8h6065944@repoman.freebsd.org>, Poul-Henning Kamp
> >  writes:
> > >
> > >  Modified files:
> > >    sys/kern             kern_proc.c 
> > >  Log:
> > >  Fix a race in destruction of sessions.
> > 
> > Not to pick on anybody, but this is a perfect example of getting locking
> > almost right:
> > 
> > BAD:
> > 
> > 	LOCK(foo->lock)
> > 	foo->refcount--;
> > 	UNLOCK(foo->lock)
> > 	if (foo->refcount == 0)
> > 		destroy(foo);
> > 
> > GOOD:
> > 
> > 	LOCK(foo->lock)
> > 	i = --foo->refcount;
> > 	UNLOCK(foo->lock)
> > 	if (i == 0)
> > 		destroy(foo);
> 
> Isn't there still a race in the GOOD case here if somone takes a new
> reference, incrementing refcount after the UNLOCK(foo->lock)?

if you had the only reference, then how didi the other party get it?

> 
> 
> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0406091042030.57882-100000>