C CRITICAL_SECTION in windows2 min read

CRITICAL_SECTION (MSDN) in Windows can be used for thread synchronization. Essentially you can create a variable and limit it’s ownership to one thread at a time.  Something like this CRITICAL_SECTION cs; volatile long counter = 0; int main(){ InitializeCriticalSection(&cs); //Create threads and run thread_func //….. //….. } void thread_func (){ //Get ownership of counter EnterCriticalSection(&cs); […]