Win7 atomic access class I have a simple atomic access class designed to work with Windows threads:

template &lt;class aa_type&gt;
class AtomicAccess{
private:
    CRITICAL_SECTION lock;
    aa_type value;
public:
    AtomicAccess(){
        InitializeCriticalSection(&amp;lock);
    }

    ~AtomicAccess(){
        DeleteCriticalSection(&amp;lock);
    }

    AtomicAccess &amp;operator=(const aa_type &amp;val){
        EnterCriticalSection(&amp;lock);
        value = val;
        LeaveCriticalSection(&amp;lock);
        return *this;
    }

    AtomicAccess &amp;operator++(int){
        EnterCriticalSection(&amp;lock);
        value++;
        LeaveCriticalSection(&amp;lock);
        return *this;
    }

    AtomicAccess &amp;operator--(int){
        EnterCriticalSection(&amp;lock);
        value--;
        LeaveCriticalSection(&amp;lock);
        return *this;
    }

    bool operator==(const aa_type &amp;val){
        aa_type current;
        EnterCriticalSection(&amp;lock);
        current = value;
        LeaveCriticalSection(&amp;lock);
        return current == val;
    }

    bool operator!=(const aa_type &amp;val){
        aa_type current;
        EnterCriticalSection(&amp;lock);
        current = value;
        LeaveCriticalSection(&amp;lock);
        return current != val;
    }
};

typedef AtomicAccess&lt;int&gt; int_aa;


Right now I am using it to only atomic-access integers, and the only operators I need are = (for assignment), ++, --, == and !=. If I decide I need more operators, I will add them.

Testing race conditions is very tricky, so I would like to ask here if my approach will work or if I am missing something.
Konrad's answer has a big advantage: it is safe!
In your code sample, if an operator raise an exception before you leave the critical section, this one will never be released. In Konrad's answer, not matter what, the critical section will be unlocked when you exit the scope, even if you don't catch an exception.