From: Grant Grundler <grundler@cup.hp.com>
To: "David S. Miller" <davem@redhat.com>
Cc: linux-kernel@vger.kernel.org, alan@lxorguk.ukuu.org.uk,
parisc-linux@thepuffingroup.com
Subject: Re: [PATCH] move xchg/cmpxchg to atomic.h
Date: Tue, 02 Jan 2001 12:39:46 -0800 [thread overview]
Message-ID: <200101022039.MAA27208@milano.cup.hp.com> (raw)
In-Reply-To: Your message of "Tue, 02 Jan 2001 01:03:48 PST." <200101020903.BAA14334@pizda.ninka.net>
David,
Sorry for being dense - but I don't see the problem in using
a spinlock to implement xchg(). The example algorithm looks broken.
Or am I missing something obvious here?
"David S. Miller" wrote:
> It is very common to do things like:
>
> producer(elem)
> {
> elem->next = list->head;
> xchg(&list->head, elem);
> }
>
> consumer()
> {
> local_list = xchg(&list->head, NULL);
> for_each(elem, local_list)
> do_something(elem);
> }
producer() looks broken. The problem is two producers can race and
one will put the wrong value of list->head in elem->next.
I think prepending to list->head needs to either be protected by a spinlock
or be a per-cpu data structure. consumer() should be ok assuming the code
can tolerate picking up "late arrivals" in the next pass.
Or am I missing something obvious here?
It's worse if producer were inlined: the arch specific optimisers might
re-order the "elem->next = list->head" statement to be quite a bit more
than 1 or 2 cycles from the xchg() operation.
thanks,
grant
Grant Grundler
Unix Systems Enablement Lab
+1.408.447.7253
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2001-01-02 21:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-01-02 11:22 Matthew Wilcox
2001-01-02 8:11 ` Grant Grundler
2001-01-02 9:03 ` David S. Miller
2001-01-02 11:21 ` David S. Miller
2001-01-02 20:44 ` Roman Zippel
2001-01-02 22:05 ` Daniel Phillips
2001-01-02 20:39 ` Grant Grundler [this message]
2001-01-02 11:59 ` Andi Kleen
2001-01-02 17:18 ` Alan Cox
2001-01-02 19:51 ` Linus Torvalds
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=200101022039.MAA27208@milano.cup.hp.com \
--to=grundler@cup.hp.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=davem@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=parisc-linux@thepuffingroup.com \
/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
all inboxes | Powered by JetHome®