Making multiple Interlocked operations atomic

xxxxx@yahoo.com wrote:

I was actually contemplating to use InterlockedPush/PopEntrySList to achieve this (I understand that it works as LIFO and I am okay with it), but was concerned that SList may add extra overhead vs locking only the index using InterlockedCompareExchange.
I will then fall back to Interlocked SList operations. Do let me know if there is any better way though.

The KEY purpose of locking is to ensure that you never leave your data
in an inconsistent state. If some dangerous thing can happen when your
operation gets interrupted between the increment and the swap, then you
must wrap the whole sequence in some kind of interlock.

However, this is something where you have to take a close look. If
nothing gets damaged by an interruption between those two operations,
then you don’t need to protect the whole sequence.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.