title: Why do atomic operations like fetch-and-add return the old value of the variable being changed?
body: <p>I am trying to learn and get better at understanding multithreading, but I got hung up on the behavior of atomic functions like fetch-and-add. In the specific case of fetch-and-add, it is my understanding that a value (let's say x which currently equals 5) is added to by an increment value (let's say 3), the resulting sum (8) is written to x's place in memory, yet the old value (5) is returned. </p>
  
  <p>There are several other such functions in different places (like OpenGL's atomic functions, Java's AtomicIntegers, and many more areas) that behave like this. But what I don't understand is why a place in code would want to write to memory and yet still return the value that it wanted to modify in the first place. Can anyone help shed light on this?</p>