I am developing a system that uses shared memory and interlocked functions.
Let’s assume i have volatile unsigned int n, a, b. I want to do the following pseudocode atomicly:
if (a <= n && n < b)
{
n++;
}
else
{
//Do nothing
}
How would I do that? Can you use multiple Interlocked functions together?
You need a lock or a CAS type operation. No amount of
volatileis going to help here. Neither will a true atomic data type.