Thread: atomic operation of reference assignment?

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    atomic operation of reference assignment?

    Hello everyone,


    I have not found any support document about whether the operation of reference variable assignment is atomic or not.

    For example, foo1 and foo2 are both reference variable of type Foo. Is foo1 = foo2 atomic? Any support documents?


    thanks in advance,
    George

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by George2 View Post
    Hello everyone,


    I have not found any support document about whether the operation of reference variable assignment is atomic or not.

    For example, foo1 and foo2 are both reference variable of type Foo. Is foo1 = foo2 atomic? Any support documents?


    thanks in advance,
    George
    That would very much depend on:
    1. The type Foo - it must be a simple type (e.g int, char, etc). Complex types (e.g. class, struct etc) are almost guaranteed to NOT be atomic. The compiler MAY find it possible to do it, but it's by no means guaranteed, and it's certainly NOT going to happen for large structures (more than say 8 or 16 bytes for sure).
    2. The compiler - the compiler is allowed to do as it likes with accesses. You can sort of expect the compiler to do a good job of it on simple types, but there's absolutely no guarantee.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Replies: 39
    Last Post: 11-30-2007, 02:16 AM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM