Is incr/decr atomic in multithread mode?
dormando at rydia.net
Mon Feb 25 06:51:47 UTC 2008
I think this is fine?
Since the operations are independently atomic, it's perfectly valid for
two threads to incr the same value.
It's possible that with two threads (A, B):
X -> set "foo" 1
A -> incr "foo" by 1
B -> incr "foo" by 1
A -> returns 3
B -> returns 3
The only guarantee the slabber makes for returning values, is that they
won't get deleted before being transferred through the network.
Could be wrong, but that's my impression from checking the sources.
Steve Chu wrote:
> In 'process_arithmetic_command' function:
> We first do item_get from slabs and then do add_delta to incr/decr the value.
> My question is:
> Is this atomic in multithread mode? Item_get is atomic and so is
> add_delta because they are protected by mutex. But the entire two
> operations seems NOT atomic. Two threads can both do item_get with
> same key, then both incr it, and write back.
> Anybody can tell me whether it is a bug or not?
> Steve Chu
More information about the memcached