For example, I have a method called increase
.
public synchronized void increase() {
count++;
}
Two threads (T_1
and T_2
) both execute this method. We know count++
is a compound operation that consists of read
, modify
and write
. If T_1
gets the lock firstly, execute read
, can T_1
be interrupted at this point (Although T_2
can't do anything besides waiting for the lock to be released)?
From Concurrency in Go by Katherine Cox-Buday, it says:
When something is considered atomic, or to have the property of atomicity, this means that within the context that it is operating, it is indivisible, or uninterruptible.
I think it means that atomicity is truly uninterruptible.
But from one answer to java - What does "atomic" mean in programming? - Stack Overflow, it says:
"Atomic operation" means an operation that appears to be instantaneous from the perspective of all other threads. You don't need to worry about a partly complete operation when the guarantee applies.
I think it means that atomicity is virtually uninterruptible (it can be interrupted, but from the perspective of all other threads, it seems it can't be interrupted.).
So, which one is right?