From: "\"Kirill Korotaev\" " <firstname.lastname@example.org>
Subject: atomic_set & gcc. atomicity question
Date: Thu, 31 Jul 2003 14:00:06 +0400 [thread overview]
Message-ID: <E19iAEA-0006Fyemail@example.com> (raw)
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?
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
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:
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* 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).