cvs commit: src/sys/kern kern_proc.c

Pawel Jakub Dawidek pjd at FreeBSD.org
Wed Jun 9 18:14:36 GMT 2004


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 at phk.freebsd.dk> said:
+> 
+> > 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:
+> 
+> > 	LOCK(foo->lock)
+> > 	i = --foo->refcount;
+> > 	UNLOCK(foo->lock)
+> > 	if (i == 0)
+> > 		destroy(foo);
+> 
+> I think it's clearer if you write:
+> 
+> 	LOCK(foo->lock);
+> 	if (--foo->refcount == 0)
+> 		destroy(foo);	/* expects a locked foo */
+> 	else
+> 		UNLOCK(foo);
+> 
+> ...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.

-- 
Pawel Jakub Dawidek                       http://www.FreeBSD.org
pjd at FreeBSD.org                           http://garage.freebsd.pl
FreeBSD committer                         Am I Evil? Yes, I Am!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/cvs-src/attachments/20040609/0a91a035/attachment.bin


More information about the cvs-src mailing list