网站首页  词典首页

请输入您要查询的函数:

 

术语 initializecriticalsectionex
释义 InitializeCriticalSectionEx
语法:
C++
BOOL WINAPI InitializeCriticalSectionEx(
__out LPCRITICAL_SECTION lpCriticalSection,
__in DWORD dwSpinCount,
__in DWORD Flags
);
InitializeCriticalSectionEx功能
初始化一个自旋数和可选的标志关键部分对象。
参数
lpCriticalSection [out]
一个临界区对象的指针。
dwSpinCount [in]
为临界区对象的旋转数。在单处理器系统,旋转数被忽略,关键节自旋计数设置为0(零)。多处理器系统上,如果临界区不可用,调用线程在执行自旋与关键部分相关联的信号等待操作dwSpinCount倍。如果临界区将在这旋转行动自由,避免调用线程等待操作。
标志 [in]
此参数可以是0或下面的值。
ValueMeaning
CRITICAL_SECTION_NO_DEBUG_INFOThe关键部分是创造了一个没有调试信息。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零(0)。为了获得更多错误信息,调用GetLastError。
备注
单个进程的线程可以使用一个互斥同步临界区对象。目前没有关于以保证线程获得临界区的所有权,但是,该系统是公平的所有线程。
这个过程负责分配一个关键节对象,它可以通过声明类型的CRITICAL_SECTION的变量使用的内存。在使用一个关键部分,这一进程的某个线程必须初始化的对象。随后修改,您可以通过调用SetCriticalSectionSpinCount函数的旋转数。
经过一个临界区对象初始化,该进程的线程可以指定在加锁,TryEnterCriticalSection,或LeaveCriticalSection对象的功能,提供互相排斥的访问共享资源。对于不同进程之间的类似线程同步,使用互斥对象。
一个关键部分对象不能移动或复制。这一进程也绝不能修改该对象,但必须把它作为逻辑不透明。只能使用临界区的管理职能,关键节对象。当您使用完的关键部分,调用DeleteCriticalSection函数。
临界区对象必须删除才能重新初始化。初始化一个关键节已初始化未定义的行为的结果。
自旋计数有益的短暂时间,可以体验高争的关键部分。考虑最坏的情况,其中一个在SMP系统中的应用有两个或三个线程不断地分配和释放的堆内存。该应用程序序列化的关键节堆。在最坏的情况下,对关键节的争夺是恒定的,并且每个线程使得对昂贵WaitForSingleObject函数调用。然而,如果旋转计数设置正确,调用线程不会立即调用WaitForSingleObject时争发生。相反,调用线程可以获取临界区的所有权,如果是,在旋转操作释放。
您可以显着改善性能选择了短暂的临界区小旋转数。堆管理器使用的每堆临界区的大约4000个旋转的罪名。这使几乎所有的最坏情况下强大的性能和可扩展性。
要求:
client最低支持Vista
server最低支持 Windows Server 2008
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
临界区对象
DeleteCriticalSection
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==InitializeCriticalSectionEx Function
Initializes a critical section object with a spin count and optional flags.
Syntax
C++
BOOL WINAPI InitializeCriticalSectionEx(
__out LPCRITICAL_SECTION lpCriticalSection,
__in DWORD dwSpinCount,
__in DWORD Flags
);
Parameters
lpCriticalSection [out]
A pointer to the critical section object.
dwSpinCount [in]
The spin count for the critical section object. On single-processor systems, the spin count is ignored and the critical section spin count is set to 0 (zero). On multiprocessor systems, if the critical section is unavailable, the calling thread spin dwSpinCount times before performing a wait operation on a semaphore associated with the critical section. If the critical section becomes free during the spin operation, the calling thread avoids the wait operation.
Flags [in]
This parameter can be 0 or the following value.
ValueMeaning
CRITICAL_SECTION_NO_DEBUG_INFOThe critical section is created without debug information.

Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero (0). To get extended error information, call GetLastError .
Remarks
The threads of a single process can use a critical section object for mutual-exclusion synchronization. There is no guarantee about the order that threads obtain ownership of the critical section, however, the system is fair to all threads.
The process is responsible for allocating the memory used by a critical section object, which it can do by declaring a variable of type CRITICAL_SECTION. Before using a critical section, some thread of the process must initialize the object. You can subsequently modify the spin count by calling the SetCriticalSectionSpinCount function.
After a critical section object is initialized, the threads of the process can specify the object in the EnterCriticalSection , TryEnterCriticalSection , or LeaveCriticalSection function to provide mutually exclusive access to a shared resource. For similar synchronization between the threads of different processes, use a mutex object.
A critical section object cannot be moved or copied. The process must also not modify the object, but must treat it as logically opaque. Use only the critical section functions to manage critical section objects. When you have finished using the critical section, call the DeleteCriticalSection function.
A critical section object must be deleted before it can be reinitialized. Initializing a critical section that is already initialized results in undefined behavior.
The spin count is useful for critical sections of short duration that can experience high levels of contention. Consider a worst-case scenario, in which an application on an SMP system has two or three threads constantly allocating and releasing memory from the heap. The application serializes the heap with a critical section. In the worst-case scenario, contention for the critical section is constant, and each thread makes an expensive call to the WaitForSingleObject function. However, if the spin count is set properly, the calling thread does not immediately call WaitForSingleObject when contention occurs. Instead, the calling thread can acquire ownership of the critical section if it is released during the spin operation.
You can improve performance significantly by choosing a small spin count for a critical section of short duration. The heap manager uses a spin count of roughly 4000 for its per-heap critical sections. This gives great performance and scalability in almost all worst-case scenarios.
Requirements
Minimum supported clientWindows Vista
Minimum supported serverWindows Server 2008
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
Critical Section Objects
DeleteCriticalSection
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms683477(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:22:26