ReleaseSemaphore

  BOOL ReleaseSemaphore(hSemaphore, cRelease, lplPrevious)    
  HANDLE hSemaphore; /* identifies the semaphore to release */
  LONG cRelease; /* count to add to current count */
  LPLONG lplPrevious; /* address for previous count */

The ReleaseSemaphore function releases ownership of the specified semaphore object.

Parameters

hSemaphore

Specifies an open handle to a semaphore object. The handle must have SEMAPHORE_MODIFY_STATE access to the semaphore.

cRelease

Specifies a number to be added to the current count for the semaphore. The count must be greater than zero and less than the maximum value specified for the semaphore.

If the value specified by cRelease would cause the maximum count for the semaphore to be exceeded, the count for the semaphore is not changed and the ReleaseSemaphore function returns FALSE.

lplPrevious

Points to a variable to be set to the previous count for the semaphore. This parameter can be set to NULL if the previous count is not required.

Return Value

The return value is TRUE if the function was successful, or FALSE if an error occurred. Use the GetLastError function to obtain extended error information.

Comment

When the semaphore is released, the current count of the semaphore is incremented by cRelease. Any threads that are waiting for the semaphore are examined to see if the current semaphore value is sufficient to satisfy their wait.

See Also

CreateSemaphore