Using the WaitForSingleObject Function.
If the function is called and times out, does it still need to release the mutex?
i.e. should ReleaseMutex be in position 1. or 2. if the five seconds elapse?
WaitForSingleObject(5 second time out)
{
//access shared resource
//1. - ReleaseMutex() here?
}
//2. - ReleaseMutex() here?
No. If the call to
WaitForSingleObjecttimes out then you have not acquired the mutex, so should not release it.i.e. you only need
ReleaseMutexat position 1.