views:

741

answers:

3

MSDN says

If the function fails, the return value is WAIT_FAILED. To get extended error information, call GetLastError.

The code is:

HANDLE     m_mutex_handle;    /**< m_mutex_handle. The handle to the created mutex. */
m_mutex_handle = ::CreateMutex( 0, false, NULL );
::WaitForSingleObject( m_mutex_handle, INFINITE );

But what are the reasons that could happen?

+3  A: 

Passing in a bogus object might cause that.

Passing in a _seriously_ bogus object may even cause undefined behaviour, but perhaps the function checks for those cases. :-P
Chris Jester-Young
+1  A: 

Closing a handle while the handle is being waited on can also cause undefined behaviour.

Windows programmer
+5  A: 

If you lack the SYNCHRONIZE privilege on the object, then you cannot wait. WAIT_FAILED will be returned.

1800 INFORMATION