................... ..
Static CthreadMutext G_locksomething;
// a Function That Want to Access Some Thing
...
Cguard
// A c class wrapper to simplify the use of CRITICAL_SECTIONclass CThreadMutex {public: CThreadMutex () {:: InitializeCriticalSection (& m_cs);} ~ CThreadMutex () {:: DeleteCriticalSection (& m_cs);} void Enter () const {:: EnterCriticalSection ((Lpcritical_section) & m_cs);} void Leave () const {: LeavecriticalSection ((lpcritical_section) & m_cs);
#if (_WIN32_WINNT> = 0x0400) BOOL TRYENTER () const {return :: tryentercriticalsection ((lpcritical_section) & m_cs);} #ENDIF / * _WIN32_WINNT> = 0x0400 * /
Private: critical_section m_cs;
Hidden_copy (cthreadmutex); MEM_LEAK_DETECT;
// Gurad class that use stack to autoly perform lock and unloack actiontemplate