Interlocked Exchange of a struct

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?

6
задан mkaes 24 May 2011 в 11:40
поделиться