/* Sample C/C++, Windows, link to kernel32.dll */
#include <windows.h>
static CRITICAL_SECTION cs;
/* Initialize the critical section before entering multi-threaded context. */
InitializeCriticalSection(&cs);
void f()
{
/* Enter the critical section -- other threads are locked out */
EnterCriticalSection(&cs);
/* Do some thread-safe processing! */
/* Leave the critical section -- other threads can now EnterCriticalSection() */
LeaveCriticalSection(&cs);
}
/* Release system object when all finished -- usually at the end of the cleanup code */
DeleteCriticalSection(&cs);