Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2004 16:34:37 +0000
From:      Bosko Milekic <bmilekic@FreeBSD.org>
To:        Nate Lawson <nate@root.org>
Cc:        "M. Warner Losh" <imp@bsdimp.com>
Subject:   Re: cvs commit: src/sys/kern kern_proc.c
Message-ID:  <20040609163437.GA26282@freefall.freebsd.org>

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

Nate Lawson wrote:
>The only potential remaining problem is if another thread can increment
>the refcount after the unlock and i == 0 comparison but before
>"free(foo)".  In this case, you'll free an object that is still in use.
>It's safe to hold locks across free(), that's how I handle this case.
>
>-Nate

  This is not true if the object 'foo' cannot gain a reference unless
  an existing referrer passes it its own reference, which would make
  sense.

  If there is a way for a reference to 'foo' to be acquired without
  a reference to it already being held, then that code needs to be
  fixed and wherever the other reference to 'foo' is needs to ensure
  to properly increment the reference count.

  In other words, if you see that the count has hit zero in the GOOD
  code, then you know you're the last guy to have decremented the
  reference count and the only guy left referring to the object, so
  in theory, you should be the only thing allowed to GRANT an additional
  reference to 'foo'.

  Know what I mean?

  In other words, the GOOD code should be correct.

  -Bosko

 



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