Original sample code:
static MyCriticalSectionWrapper lock;
lock.Enter();
counter = ++m_counter;
lock.Leave();
I understand that the oncoming code is probably just a placeholder, however if this is really what you are trying to do, you can use the Windows function "InterlockedIncrement ()" to accomplish this. Example:
// atomic increment for thread safety
InterlockedIncrement(&m_counter);
counter = m_counter;
source
share