ReleaseSemaphore Function

The ReleaseSemaphore function increments the count of a semaphore object to a specified value.

Syntax

BOOL ReleaseSemaphore(
      HANDLE hSemaphore,
      LONG lReleaseCount,
      LPLONG lpPreviousCount
    );

Parameters

Parameter Description
hSemaphore A handle to the semaphore object. The handle must have the SEMAPHORE_RELEASE access right.
lReleaseCount The amount by which the semaphore's current count is to be increased. This value must be greater than or equal to 1.
lpPreviousCount A pointer to a variable that receives the semaphore's previous count. This parameter can be NULL.

Return Value

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

Remarks

A semaphore is a synchronization object that restricts the number of threads that can access a resource or a pool of resources concurrently.

The ReleaseSemaphore function increments the semaphore's count by the value specified by lReleaseCount. The function also returns the previous value of the semaphore's count.

If the new count specified by adding lReleaseCount to the current count exceeds the maximum count specified when the semaphore was created, the function fails and returns zero, and GetLastError returns ERROR_TOO_MANY_POSTS.

The calling thread must have appropriate access rights to the semaphore object.

When a thread calls ReleaseSemaphore, the system checks if any threads are waiting for the semaphore. If there are, the system wakes up threads from the waiting queue until the semaphore's count is zero or the number of waiting threads is exhausted.

Requirements

Requirements

Attribute Value
Minimum supported client Windows XP [desktop apps | UWP apps]
Minimum supported server Windows Server 2003 [desktop apps | UWP apps]
Header synchapi.h (include windows.h)
Library Kernel32.lib
DLL Kernel32.dll

See Also