#pragma once
class CCriticalSection2
{
private:
CRITICAL_SECTION m_cs;
public:
CCriticalSection2()
{
InitializeCriticalSection(&m_cs);
}
~CCriticalSection2()
{
DeleteCriticalSection(&m_cs);
}
inline void Enter() { EnterCriticalSection(&m_cs); }
inline void Leave() { LeaveCriticalSection(&m_cs); }
};
template<class T>
class CMultiThreadSync
{
friend class CThreadSync;
private:
static CCriticalSection2 m_Sync;
public:
class CThreadSync
{
public:
CThreadSync()
{
T::m_Sync.Enter();
}
~CThreadSync()
{
T::m_Sync.Leave();
}
};
};
template<class T>
CCriticalSection2 CMultiThreadSync<T>::m_Sync;
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// 실제사용
//
// class CMyThred : public CMultiThreadSync<CMyThred>
// {
// }
// //구현부분
//
// void CMyThread()
// {
// CThreadSync sync;
// //작업 수행
// }
//