Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2004 23:45:28 +0700
From:      Alexey Dokuchaev <danfe@nsu.ru>
To:        "M. Warner Losh" <imp@bsdimp.com>
Cc:        cvs-all@freebsd.org
Subject:   Re: cvs commit: src/sys/kern kern_proc.c
Message-ID:  <20040609164528.GB90103@regency.nsu.ru>
In-Reply-To: <20040609.100413.118633043.imp@bsdimp.com>
References:  <200406090929.i599T8h6065944@repoman.freebsd.org> <53418.1086773585@critter.freebsd.dk> <20040609.100413.118633043.imp@bsdimp.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jun 09, 2004 at 10:04:13AM -0600, M. Warner Losh wrote:
> In message: <53418.1086773585@critter.freebsd.dk>
>             "Poul-Henning Kamp" <phk@phk.freebsd.dk> writes:
> : 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);
> : 
> 
> Can you provide a couple of lines about why BAD is BAD and why GOOD
> fixes that flaw?  That should help others from making this mistake in
> the future.

Probably even document in developer's handbook, or some related manpage.

./danfe



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040609164528.GB90103>