网站首页  词典首页

请输入您要查询的函数:

 

术语 releasesemaphore
释义 ReleaseSemaphore
语法:
C++
BOOL WINAPI ReleaseSemaphore(
__in HANDLE hSemaphore,
__in LONG lReleaseCount,
__out_opt LPLONG lpPreviousCount
);
ReleaseSemaphore函数
由指定的数额增加了指定的信号灯对象计数。
参数
hSemaphore [in]
阿信号处理的对象。在CreateSemaphore或OpenSemaphore函数返回此句柄。
这种处理必须有SEMAPHORE_MODIFY_STATE访问权限。有关更多信息,请参阅同步对象的安全和访问权限。
lReleaseCount [in]
数额在该信号对象的当前计数增加。该值必须大于零。如果指定的数额将导致信号的数量超过最大计数时指定的信号量创建的计数不改变,该函数返回FALSE。
lpPreviousCount [指出,可选]
对变量的指针领取该信号灯的前一个计数。此参数可以是NULL,如果此前的数据是不需要的。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
备注
一个信号量对象的状态时,其信号计数大于零,无信号时,其计数等于零。该进程调用CreateSemaphore函数指定信号量的初始值。每一个等待线程被释放,因为信号的信号状态,信号量的计算时间减少了1。
通常,应用程序使用一个信号量限制的线程数使用资源。前一个线程使用的资源,它指定的信号在呼叫句柄在等待职能之一。当等待函数返回时,它减少了一个信号量的计数。当线程完成使用资源,它调用ReleaseSemaphore增加一个信号量的计数。
另一个ReleaseSemaphore使用过程中应用程序的初始化。应用程序可以创建一个带有初始值为零的信号。这将设置信号灯的状态,无信号,并阻止所有的线程访问受保护的资源。当应用程序完成它的初始化,它使用ReleaseSemaphore增加计数其最大价值,允许正常访问,受保护的资源。
这是不可能的,以减少使用信号量对象计数ReleaseSemaphore,因为lReleaseCount不可能是负数。暂时限制或减少访问,创建一个循环中,您调用的时间WaitForSingleObject函数时零间隔,直至信号计数减少了足够的。 (请注意,其他线程可以降低,而这个循环正在执行的数量。)恢复与发行数量等于WaitForSingleObject是在循环中调用的次数接入,电话ReleaseSemaphore。
实例
举一个例子,它使用ReleaseSemaphore,请参阅使用信号量对象。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
CreateSemaphore
OpenSemaphore
信号量对象
同步功能
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==ReleaseSemaphore Function
Increases the count of the specified semaphore object by a specified amount.
Syntax
C++
BOOL WINAPI ReleaseSemaphore(
__in HANDLE hSemaphore,
__in LONG lReleaseCount,
__out_opt LPLONG lpPreviousCount
);
Parameters
hSemaphore [in]
A handle to the semaphore object. The CreateSemaphore or OpenSemaphore function returns this handle.
This handle must have the SEMAPHORE_MODIFY_STATE access right. For more information, see Synchronization Object Security and Access Rights .
lReleaseCount [in]
The amount by which the semaphore object's current count is to be increased. The value must be greater than zero. If the specified amount would cause the semaphore's count to exceed the maximum count that was specified when the semaphore was created, the count is not changed and the function returns FALSE.
lpPreviousCount [out, optional]
A pointer to a variable to receive the previous count for the semaphore. This parameter can be NULL if the previous count is not required.
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 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.
It is not possible to reduce the semaphore object count using ReleaseSemaphore, because lReleaseCount cannot be a negative number. To temporarily restrict or reduce access, create a loop in which you call the WaitForSingleObject function with a time-out interval of zero until the semaphore count has been reduced sufficiently. (Note that other threads can reduce the count while this loop is being executed.) To restore access, call ReleaseSemaphore with the release count equal to the number of times WaitForSingleObject was called in the loop.
Examples
For an example that uses ReleaseSemaphore, see Using Semaphore Objects .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
CreateSemaphore
OpenSemaphore
Semaphore Objects
Synchronization Functions
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms685071(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:25:29