如果我像这样定义模板结构:
template <typename T>
struct SYNCHED_DATA
{
SYNCHED_DATA()
{
hMutex = ::CreateMutex(NULL, FALSE, NULL);
}
~SYNCHED_DATA()
{
if(hMutex)
CloseHandle(hMutex);
hMutex = NULL;
}
void set(T* pV)
{
if(pV)
{
::WaitForSingleObject(hMutex, INFINITE);
var = *pV;
::ReleaseMutex(hMutex);
}
}
void get(T* pV)
{
if(pV)
{
::WaitForSingleObject(hMutex, INFINITE);
*pV = var;
::ReleaseMutex(hMutex);
}
}
private:
HANDLE hMutex;
T var;
SYNCHED_DATA(const SYNCHED_DATA& s)
{
}
SYNCHED_DATA& operator = (const SYNCHED_DATA& s)
{
}
};
我可以确定那些 WaitForSingleObject() API 将始终返回 WAIT_OBJECT_0 吗?如果不是,在什么情况下他们会失败,我应该如何处理?