Olav Sandstaa wrote:
>>
>> There isn't much difference in cost between a lock(Shared)/unlock and
>> addRef/release. Each requires a pair of interlocked instructions.
>
> Thanks for the clearification about the cost. I expected the interlock
> instruction to be relatively cheaper than a shared lock.
>
>
My performance testing suggests that on Intel and AMD, an interlocked
CAS is cheaper than an interlocked increment or decrement. I suspect
this is because the interlocked CAS is a single memory operation that
either succeeds or fails in the memory controller while the interlocked
increment (actually a "add 1 to memory") requires a memory bus lock
while the processors fetches the operand, does the add, and writes it back.
This further suggests that we might get some bang by replacing our
interlocked increment and decrement with interlocked CASes.
--
Jim Starkey
President, NimbusDB, Inc.
978 526-1376