Search code examples
javaasynchronousatomicsynchronous

Are "atomic" and "synchronous" synonyms in programming?


Do "atomic" and "synchronous" mean the same thing or are there some minute differences?

Looking at the answers to this question, I think the answer to my question is yes, they're synonyms. Are the following true in general?

  • a synchronous operation will complete before the next operation starts
  • an atomic operation is the same as a synchronous operation
  • an asynchronous operation will complete at some point before or after the next operation starts

Solution

  • Not quite the same. An atomic operation is one that can't be subdivided into smaller parts. So, in Java, assigning to an int is atomic: nothing can interrupt it, it either completes or doesn't.

    A synchronous operation is one that simulates being atomic through some programming mechanism you invoke using the synchronized keyword. The implementation of that can vary.So in a synchronized block, the run time system enforces what's called a critical region in which only one thread of control can pass at the same time.