Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2004 19:37:47 +0200
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc:        cvs-all@FreeBSD.ORG
Subject:   Re: cvs commit: src/sys/kern kern_proc.c
Message-ID:  <20040609173747.GT12007@darkness.comp.waw.pl>
In-Reply-To: <200406091629.i59GTnCx052623@khavrinen.lcs.mit.edu>
References:  <20040609.100413.118633043.imp@bsdimp.com> <55929.1086798000@critter.freebsd.dk> <200406091629.i59GTnCx052623@khavrinen.lcs.mit.edu>

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

--HC0F8i/BfMshQzR8
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Jun 09, 2004 at 12:29:49PM -0400, Garrett Wollman wrote:
+> <<On Wed, 09 Jun 2004 18:20:00 +0200, "Poul-Henning Kamp" <phk@phk.freeb=
sd.dk> said:
+>=20
+> > The way to fix this is to make sure that the test for zero-ness
+> > is done on the result of our own decrement operation:
+>=20
+> > 	LOCK(foo->lock)
+> > 	i =3D --foo->refcount;
+> > 	UNLOCK(foo->lock)
+> > 	if (i =3D=3D 0)
+> > 		destroy(foo);
+>=20
+> I think it's clearer if you write:
+>=20
+> 	LOCK(foo->lock);
+> 	if (--foo->refcount =3D=3D 0)
+> 		destroy(foo);	/* expects a locked foo */
+> 	else
+> 		UNLOCK(foo);
+>=20
+> ...and also a bit harder to mess up in maintenance (particularly if
+> destroy() asserts that the lock is held).

No, it is still wrong. The only good way is green's way.
You cannot destroy object even if you held its lock, because another
thread can sleep on this lock and it will be destroyed under it.

So first of all one have to lock whole list of element before will
take one of then and then remove it from the list before list-lock
is released.

--=20
Pawel Jakub Dawidek                       http://www.FreeBSD.org
pjd@FreeBSD.org                           http://garage.freebsd.pl
FreeBSD committer                         Am I Evil? Yes, I Am!

--HC0F8i/BfMshQzR8
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAx0rrForvXbEpPzQRAtc4AKCuzk5gBVW4Oe2MU5h7MwN3ufCWIgCg1Rlt
CSu5aw95eahlpqh6lx/B2s0=
=3OQZ
-----END PGP SIGNATURE-----

--HC0F8i/BfMshQzR8--



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