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 WaitForSingleObject
times out then you have not acquired the mutex, so should not release it.
i.e. you only need ReleaseMutex
at position 1.
Your case #1 is correct. If you time out on that call, it means the resource was not acquired and you should not attempt to release it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With