class CriticalSection { public: CriticalSection ( ) { InitializeCriticalSection ( &m_CritSec ); } ~CriticalSection ( ) { DeleteCriticalSection ( &m_CritSec ); } void Acquire ( ) { EnterCriticalSection ( &m_CritSec ); } void Release ( ) { LeaveCriticalSection ( &m_CritSec ); } public: CRITICAL_SECTION m_CritSec; }; 也可以在定义一个类模版 template <class T> class SyncLock { public: SyncLock ( T& obj ) : m_SyncObject ( obj ) { m_SyncObject.Acquire ( ); } ~SyncLock() { m_SyncObject.Release ( ); } private: T& m_SyncObject; }; typedef SyncLock<CriticalSection> CriticalSectionLock; 具体用法如下: