atomic_set & gcc. atomicity question

From: Q?=Kirill KorotaevQ=20?= (kksx_at_mail.ru)
Date: 07/31/03

  • Next message: Tomas Szepe: "Re: module-init-tools don't support gzipped modules."
    To: linux-kernel@vger.kernel.org
    Date:	Thu, 31 Jul 2003 14:00:06 +0400
    
    

    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

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Tomas Szepe: "Re: module-init-tools don't support gzipped modules."

    Relevant Pages

    • Re: Question on atomic_inc/dec
      ... >> use directly the kernel stuff unless you are coding kernel stuff. ... > Is there any reason NOT to use the atomic ops in user-space? ... send the line "unsubscribe linux-kernel" in ... Please read the FAQ at http://www.tux.org/lkml/ ...
      (Linux-Kernel)
    • Kernel 2.6.0-test9 Zombie Issue
      ... Zombies for any short lived processes. ... kernel. ... Is this something in the FAQ? ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • ps2 mouse
      ... I compiled 2.6.1 kernel on my computer and the behavior of my mouse is ... I have read also the FAQ about problems in input subsystem for 2.6, ... send the line "unsubscribe linux-kernel" in ... Please read the FAQ at http://www.tux.org/lkml/ ...
      (Linux-Kernel)
    • [bernie@develer.com: Kernel 2.6 size increase]
      ... code bloat can be very harmful on embedded targets, ... kernel configuration for ColdFire: ... send the line "unsubscribe linux-kernel" in ... Please read the FAQ at http://www.tux.org/lkml/ ...
      (Linux-Kernel)
    • RE: Linux 2.6.5 emu10k1 module FAILS, built-in OK.
      ... grep: networking/netif-msg.txt: Permission denied ... this is with _SMP_ kernel only, ... Please read the FAQ at http://www.tux.org/lkml/ ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)