curr_sequence = (UCHAR) InterlockedIncrement(&last_sequence);

refcount = InterlockedDecrement(&This->RefCount);

		InitializeCriticalSection(&g_cs);
		MeasureConcurrentOperation(TEXT("Critical Section"), nThreads, CriticalSectionCallback);
		// Don't forget to cleanup
		DeleteCriticalSection(&g_cs);

  

void WINAPI CriticalSectionCallback()
{
	EnterCriticalSection(&g_cs);
	gv_value = 0;
	LeaveCriticalSection(&g_cs);
}

  Slim Reader/Writer lock

      // Prepare the Slim Reader/Writer lock
		InitializeSRWLock(&g_srwLock);
		MeasureConcurrentOperation(TEXT("SRWLock Read"), nThreads, SRWLockReadCallback);
		MeasureConcurrentOperation(TEXT("SRWLock Write"), nThreads, SRWLockWriteCallback);
		// NOTE: You can't cleanup a Slim Reader/Writer lock

  

void WINAPI SRWLockReadCallback() {
	AcquireSRWLockShared(&g_srwLock);
	gv_value = 0;
	ReleaseSRWLockShared(&g_srwLock);
}

  

the mutex

		// Prepare the mutex
		g_hMutex = CreateMutex(NULL, false, NULL);
		MeasureConcurrentOperation(TEXT("Mutex"), nThreads, MutexCallback);
		CloseHandle(g_hMutex);

  

HANDLE g_hMutex;
void WINAPI MutexCallback()
{
	WaitForSingleObject(g_hMutex, INFINITE);
	gv_value = 0;
	ReleaseMutex(g_hMutex);
}

  

 有两种不同类型的事件对象。一种是人工重置的事件,另一种是自动重置的事件。当人工重置的事件得到通知时,等待该事件的所有线程均变为可调度线程。当一个自动重置的事件得到通知时,等待该事件的线程中只有一个线程变为可调度线程。

If this parameter is TRUE, the function creates a manual-reset event object, which requires the use of the ResetEvent function to set the event state to nonsignaled. If this parameter is FALSE, the function creates an auto-reset event object, and system automatically resets the event state to nonsignaled after a single waiting thread has been released.