...however, you need to release the mutex, if the wait was successful.
You could go with a wrapper (Pseudocode!)
class CMyMutex
{
bool haveMutex;
HANDLE mutex;
bool HasMutex() { return haveMutex; }
void Wait()
{
if (haveMutex)
return;
if (WaitForSingleObject == WAIT_OBJECT_0) {
haveMutex = true;
}
}
void Release()
{
if (haveMutex) {
haveMutex = false;
ReleaseMutex(mutex);
}
}
};
However, each thread needs it's own instance of this class. And you should add the "vanilla" stuff (correct CTor/DTor etc.)
Peter
Main Topics
Browse All Topics





by: jkrPosted on 2001-09-24 at 13:14:39ID: 6506805
>>Can anyone tell me how to check for ownership?
The only method I can think of that is 'portable' would be using a wait operation that times out:
BOOL IsMutexOwned ( HANDLE hMutex) {
DWORD dwWaitResult = WaitForSingleObject ( hMutex, 1);
return ( WAIT_TIMEOUT == dwWaitResult);
}