redis - How to understand the atomic operation of memcache?
大家讲道理2017-05-31 10:36:15
0
1
1063
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? ?
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.
Is the above statement atomic? Can the above statements be executed concurrently?+
We envision a world whereis atomic, so
+cannot be concurrent? no.
no operations are atomic.
Take the simplesti++
as an example:
The value ofi
At this time, 2 threadsis
4.
execute i++ at the same time
. (Let’s assume that simultaneous is what you call concurrency)
i++
How is it executed?
add
operation must be atomic. What we are concurring with is the
system, not the operation.