From: David Schwartz <davids@webmaster.com>
To: <ak@suse.de>
Cc: Brad Pepers <brad@linuxcanada.com>, <linux-kernel@vger.kernel.org>
Subject: Re: Multi-threading
Date: Wed, 13 Mar 2002 01:01:34 -0800 [thread overview]
Message-ID: <20020313090150.AAA28331@shell.webmaster.com@whenever> (raw)
In-Reply-To: <20020313092306.A5570@wotan.suse.de>
On Wed, 13 Mar 2002 09:23:06 +0100, Andi Kleen wrote:
>>If it was in public view, whatever held it in public view would be
>> using it,
>>and hence its use count could not drop to zero.
>That's not correct at least in the usual linux kernel pattern of using
>reference counts for objects. Hash tables don't hold reference counts,
>only users do. If you think about it a hash table or global list holding
>a reference count doesn't make too much sense.
That's the way I've always done it and it has saved me a lot of heartache. A
use count of 'zero' means that it's really not used at all, and hence nothing
would have any way of finding it. Anything with a future interest in
something should 'use' it.
In any event, hash tables require locks themselves anyway. So if you find an
object in a hash table, you must be holding some lock when you find it, so
you can increment the use count under the protection of that lock. The trick
becomes the decrement operation, because ideally you'd prefer not to have to
lock the hash table again unless you have to remove the object.
I believe, however, that you are completely safe if you decrement the use
count atomically, and if it's zero, you grab the hash lock, confirm that the
use count is still zero, and then remove the object.
Since the use count is always locked for the first time in any usage chain
with the hash lock held (lock it when you find it), an increment from zero to
one can only occur while the lock is held. So if you hold the lock, an
increment from zero to one cannot occur. No race.
DS
next prev parent reply other threads:[~2002-03-13 9:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20020311182111Z310364-889+120750@vger.kernel.org.suse.lists.linux.kernel>
2002-03-11 21:54 ` Multi-threading Andi Kleen
2002-03-12 0:02 ` Multi-threading Brad Pepers
[not found] ` <20020312000310.DBCF41EDB9@Cantor.suse.de>
2002-03-12 7:10 ` Multi-threading Andi Kleen
2002-03-13 7:51 ` Multi-threading David Schwartz
2002-03-13 8:23 ` Multi-threading Andi Kleen
2002-03-13 9:01 ` David Schwartz [this message]
2002-03-14 4:50 ` Multi-threading Rusty Russell
2002-03-11 19:36 Multi-threading Dipankar Sarma
2002-03-11 23:53 ` Multi-threading Brad Pepers
-- strict thread matches above, loose matches on Subject: below --
2002-03-11 18:20 Multi-threading Brad Pepers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020313090150.AAA28331@shell.webmaster.com@whenever \
--to=davids@webmaster.com \
--cc=ak@suse.de \
--cc=brad@linuxcanada.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox