Critical sections will work (they are lighter than mutexes). InitializeCriticalSection, EnterCriticalSection, LeaveCriticalSection and DeleteCriticalSection are the functions to look up in MSDN.
void func() {
EDIT: Critical sections are faster than mutexes, since critical sections are primarily user-mode primitives. In the case of non-contact receipt (usually this is a usual case), there is no system call to the kernel, and the receipt takes about tens of cycles. The kernel switch is more expensive (about a hundred cycles). The only time that critical sections are called to the kernel is a lock, which includes waiting on the kernel primitive (either a mutex or an event). Acquiring a mutex always involves a call to the kernel and, therefore, is an order of magnitude slower. However, critical sections can only be used to synchronize resources in a single process. A mutex is required to synchronize multiple processes.
Michael
source share