From: "\"Kirill Korotaev\" " <kksx@mail.ru>
To: linux-kernel@vger.kernel.org
Subject: atomic_set & gcc. atomicity question
Date: Thu, 31 Jul 2003 14:00:06 +0400 [thread overview]
Message-ID: <E19iAEA-0006Fy-00.kksx-mail-ru@f6.mail.ru> (raw)
Hi!
Thinking about atomicity of some operations in kernel I've got the following question about atomic_XXX operations.
atomic_set and atomic_read (on i386+ and some others) are simple write to and read from memory, i.e. they are defined as:
#define atomic_set(v,i) (((v)->counter) = (i))
#define atomic_read(v) ((v)->counter)
If we call atomic_set() with constant 2nd argument it's ok - it's a simple write to var. But what if we do atomic_set(var, var1+var2)?
Probably, it can happen that compiler will do "var=var1; var+=var2", can't it? If so, atomic_read() can return intermediate value and write won't seem atomic at all. Who guarentees that compiler won't compile it this way? Optimization? gcc developers?
Kirill
next reply other threads:[~2003-07-31 10:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-31 10:00 "Kirill Korotaev" [this message]
2003-07-31 10:46 ` atomic_set & gcc. atomicity question Raj Inguva
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=E19iAEA-0006Fy-00.kksx-mail-ru@f6.mail.ru \
--to=kksx@mail.ru \
--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;
as well as URLs for NNTP newsgroup(s).