linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* atomic_set & gcc. atomicity question
@ 2003-07-31 10:00 "Kirill Korotaev" 
  2003-07-31 10:46 ` Raj Inguva
  0 siblings, 1 reply; 2+ messages in thread
From: "Kirill Korotaev"  @ 2003-07-31 10:00 UTC (permalink / raw)
  To: linux-kernel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-07-31 10:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-31 10:00 atomic_set & gcc. atomicity question "Kirill Korotaev" 
2003-07-31 10:46 ` Raj Inguva

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).