Say, I have the following code:
Do I need to worry about WaitForSingleObject() and/or ReleaseMutex() failing in this case?Code: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) { } };




Reply With Quote