The ReleaseSemaphore function increases the count of the specified semaphore object by a specified amount.
BOOL ReleaseSemaphore(
HANDLE hSemaphore, |
// handle of the semaphore object |
LONG lReleaseCount, |
// amount to add to current count |
LPLONG lpPreviousCount |
// address of previous count |
); |
Windows NT: This handle must have SEMAPHORE_MODIFY_STATE access. For
more information, see Interprocess
Synchronization Objects.
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.
The state of a semaphore object is signaled when its count is greater than zero and nonsignaled when its count is equal to zero. The process that calls the CreateSemaphore function specifies the semaphore’s initial count. Each time a waiting thread is released because of the semaphore’s signaled state, the count of the semaphore is decreased by one.
Typically, an application uses a semaphore to limit the number of threads using a resource. Before a thread uses the resource, it specifies the semaphore handle in a call to one of the wait functions. When the wait function returns, it decreases the semaphore’s count by one. When the thread has finished using the resource, it calls ReleaseSemaphore to increase the semaphore’s count by one.
Another use of ReleaseSemaphore is during an application’s initialization. The application can create a semaphore with an initial count of zero. This sets the semaphore’s state to nonsignaled and blocks all threads from accessing the protected resource. When the application finishes its initialization, it uses ReleaseSemaphore to increase the count to its maximum value, to permit normal access to the protected resource.
CreateSemaphore, OpenSemaphore
file: /Techref/os/win/api/win32/func/src/f73_19.htm, 4KB, , updated: 2000/4/7 11:19, local time: 2024/11/5 00:38,
3.145.178.159:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://linistepper.com/techref/os/win/api/win32/func/src/f73_19.htm"> ReleaseSemaphore</A> |
Did you find what you needed? |