cvs commit: src/sys/kern kern_proc.c

Doug Rabson dfr at nlsystems.com
Wed Jun 9 16:25:05 GMT 2004


On Wed, 2004-06-09 at 10:33, Poul-Henning Kamp wrote:
> In message <200406090929.i599T8h6065944 at 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)?




More information about the cvs-all mailing list