6 Replies Latest reply: Feb 18, 2013 2:20 AM by Kayaman RSS

    Atomic operation?

    Murray9654
      When i am going through java docs i have encountered the following statement about Atomic action

      " An atomic action cannot stop in the middle: it either happens completely, or it doesn't happen at all. No side effects of an atomic action are visible until the action is complete."

      So i understand this as, A thread does not give up(does not move out of running state) until it completes the atomic action(a sequence of steps). So atomic action done by one thread is visible to all the threads. i mean to say no other thread executes until the the thread that is executing the atomic action completes. so any modification done by atomic action will be visible to other threads.

      Is my understanding right? Did I understood this rightly?

      Edited by: Muralidhar on Feb 16, 2013 5:37 PM
        • 1. Re: Atomic operation?
          EJP
          That's not what it actually says. It just says the effects aren't visible until the action competes. What you've described is one possible way of implementing that.
          • 2. Re: Atomic operation?
            801554
            Atomic operation is totally different thing from visibility. When a Thread is executing atomic operation, it means no other thread have a chance to disturb the action, but it does not garantee other Threads can "see" the result of the operation immediately.
            • 3. Re: Atomic operation?
              Murray9654
              Just look at the part of the statement

              "An atomic action cannot stop in the middle"

              So it says that the action does not stop until it completes. so thread executing atomic does not move out of running state until it completes the action. Is that the meaning of that statement?
              • 4. Re: Atomic operation?
                EJP
                I've already answered that. Consider a database transaction. You can't claim that the thread executing it never stops, but you can't see any effect of it until it completes.
                • 5. Re: Atomic operation?
                  Murray9654
                  Done some homework. understood what you meant. Thank you.
                  • 6. Re: Atomic operation?
                    Kayaman
                    teasp wrote:
                    Atomic operation is totally different thing from visibility. When a Thread is executing atomic operation, it means no other thread have a chance to disturb the action, but it does not garantee other Threads can "see" the result of the operation immediately.
                    Well if it isn't Mr. Concurrency Expert.
                    Based on the ignorance and hostility you demonstrated in your other thread, I wouldn't start dishing out answers to people just yet.

                    Offense very much intended.