I am trying to make it clear for myself what "interlocked" exactly means. I read the following: "The interlocked functions provide a simple mechanism for synchronizing access to a variable that is shared by multiple threads. They also perform operations on variables in an atomic manner."
So could the following functions be called interlocked?
#include <QtCore>
#include <QAtomicPointer>
QAtomicInt i;
void interlockedMultiply(int factor)
{
int oldValue;
do
{
oldValue = i;
} while (!i.testAndSetOrdered(oldValue, oldValue * factor));
}
long long x;
QReadWriteLock lock;
void interlockedAdd(long long y)
{
lock.lockForWrite();
x += y;
lock.unlock();
}
If no, suggest a proper name, please.