0
点赞
收藏
分享

微信扫一扫

线程同步 win

/*
只能在当前进程中使用
只能同步一个资源,要用同步多个资源需要使用 SynMultiWaite
*/
class Synchronization
{
Synchronization(): m_dwMilliseconds(500){ m_Syn = CreateMutex(NULL,false,NULL);}
Synchronization(DWORD dwMill): m_dwMilliseconds(500){ m_Syn = CreateMutex(NULL,false,NULL);}
~Synchronization() { CloseHandle(m_Syn);}
public:
/*
WAIT_ABANDONED
The specified object is a mutex object that was not released
by the thread that owned the mutex object before the owning
thread terminated. Ownership of the mutex object is granted
to the calling thread, and the mutex is set to nonsignaled.
WAIT_OBJECT_0
The state of the specified object is signaled.
WAIT_TIMEOUT
The time-out interval elapsed, and the object's state is nonsignaled.
*/
DWORD SynSingleWaite(){ return WaitForSingleObject(m_Syn,m_ulMilliseconds); }
bool SynRelease(){ return ReleaseMutex(m_Syn); } //when use mutl
//DWORD SynMultiWaite(){ DWORD WaitForMultipleObjects();}
private:
HANDLE m_Syn;
DWORD m_dwMilliseconds;
};

举报

相关推荐

0 条评论