Export (0) Print
Expand All
Expand Minimize
0 out of 7 rated this helpful - Rate this topic

ReleaseMutex function

Releases ownership of the specified mutex object.

Syntax


BOOL WINAPI ReleaseMutex(
  _In_  HANDLE hMutex
);

Parameters

hMutex [in]

A handle to the mutex object. The CreateMutex or OpenMutex function returns this handle.

Return value

If the function succeeds, the return value is nonzero.

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

Remarks

The ReleaseMutex function fails if the calling thread does not own the mutex object.

A thread obtains ownership of a mutex either by creating it with the bInitialOwner parameter set to TRUE or by specifying its handle in a call to one of the wait functions. When the thread no longer needs to own the mutex object, it calls the ReleaseMutex function so that another thread can acquire ownership.

A thread can specify a mutex that it already owns in a call to one of the wait functions without blocking its execution. This prevents a thread from deadlocking itself while waiting for a mutex that it already owns. However, to release its ownership, the thread must call ReleaseMutex one time for each time that it obtained ownership (either through CreateMutex or a wait function).

Windows Phone 8: This API is supported.

Windows Phone 8.1: This API is supported.

Examples

For an example that uses ReleaseMutex, see Using Mutex Objects.

Requirements

Minimum supported client

Windows XP [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2003 [desktop apps | Windows Store apps]

Header

WinBase.h on Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2 (include Windows.h);
Synchapi.h on Windows 8 and Windows Server 2012

Library

Kernel32.lib

DLL

Kernel32.dll

See also

CreateMutex
Mutex Objects
Synchronization Functions

 

 

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.