I want to use InterlockedExchange from the WinAPI to use a lock free synchronization of threads.
At the moment I have a class like this.
struct DataExchange
{
volatile LONG m_value;
void SetValue(LONG newVal)
{
InterlockedExchange(&m_value, newVal);
}
LONG GetValue()
{
LONG workVal=0;
InterlockedExchange(&workVal, m_value);
return workVal;
}
};
One thread can set a new value and an other thread can read this value.
Now what I want to do is to change the LONG
value to be a struct
.
Is there any way in the WinAPI how I can copy a struct
lock free?
struct
is larger than 32 bits. But what you can do is exchange a pointer to astruct
. – SikaGetValue
implementation corrupts the value... – Thunderstone