Memcache's add is atomic, that is, multiple processes are performing add operations at the same time, and no race conditions will occur. Does this mean that add will not generate concurrency? ?
某草草2017-05-31 10:38:15
The questioner is overthinking. It is precisely because of the atomicity of add
that we can be assured of concurrency.
You don’t know enough about the underlying concepts.
We say that concurrency of an operation is meaningless.
a = b + c;
Is the above statement atomic? Can the above statements be executed concurrently?
a = getValueOfB() + getValueOfC();
What about the one above?
a = add(getValueOfB(), getValueOfC());
What about this?
+ is atomic, so
+ cannot be concurrent? no.
no operations are atomic.
Take the simplesti++ as an example:
The value of
i is
4.
execute i++ at the same time . (Let’s assume that simultaneous is what you call concurrency)
i++ How is it executed?
But we have not encountered this situation because i++ is atomic.
So does it mean that atomicity cannot be concurrent? Yes.
who care
From a user perspective, the
add operation must be atomic. What we are concurring with is the
system, not the operation.