网站首页  词典首页

请输入您要查询的函数:

 

术语 setcriticalsectionspincount
释义 SetCriticalSectionSpinCount
语法:
C++
DWORD WINAPI SetCriticalSectionSpinCount(
__inout LPCRITICAL_SECTION lpCriticalSection,
__in DWORD dwSpinCount
);
SetCriticalSectionSpinCount功能
设置指定临界区的自旋计数。当一个线程试图获得一个关键部分是锁定纺纱方法,线程进入一个循环,检查是否锁被释放,如果不释放锁,线程进入睡眠状态。
参数
lpCriticalSection [ in , out ]
一个临界区对象的指针。
dwSpinCount [in]
为临界区对象的旋转数。在单处理器系统,旋转数被忽略,关键节自旋计数设置为零(0)。多处理器系统上,如果临界区不可用,调用线程在执行旋转与关键部分相关联的信号等待操作dwSpinCount倍。如果临界区将在这旋转行动自由,避免调用线程等待操作。
返回值
该函数返回的关键节上旋转的罪名。
备注
单个进程的线程可以使用一个互斥同步临界区对象。这个过程负责分配一个关键节对象,它可以通过声明类型的CRITICAL_SECTION的变量使用的内存。之前使用一个关键部分,一些进程中的线程必须调用InitializeCriticalSection或InitializeCriticalSectionAndSpinCount函数来初始化对象。随后修改,您可以通过调用SetCriticalSectionSpinCount函数的旋转数。
自旋计数有益的短暂时间,可以体验高争的关键部分。考虑最坏的情况,其中一个在SMP系统中的应用有两个或三个线程不断地分配和释放的堆内存。该应用程序序列化的关键节堆。在最坏的情况下,对关键节的争夺是恒定的,并且每个线程使得对昂贵WaitForSingleObject函数调用。然而,如果旋转计数设置正确,调用线程不会立即调用WaitForSingleObject时争发生。相反,调用线程可以获取临界区的所有权,如果是,在旋转操作释放。
您可以显着改善性能选择了短暂的临界区小旋转数。堆管理器使用的每堆临界区的大约4000个旋转的罪名。这使几乎所有的最坏情况下强大的性能和可扩展性。
要编译的应用程序使用此功能,定义_WIN32_WINNT为0x0403或更高版本。有关详细信息,请参阅使用Windows头。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
临界区对象
InitializeCriticalSection
InitializeCriticalSectionAndSpinCount
同步功能
WaitForSingleObject
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==SetCriticalSectionSpinCount Function
Sets the spin count for the specified critical section. Spinning means that when a thread tries to acquire a critical section that is locked, the thread enters a loop, checks to see if the lock is released, and if the lock is not released, the thread goes to sleep.
Syntax
C++
DWORD WINAPI SetCriticalSectionSpinCount(
__inout LPCRITICAL_SECTION lpCriticalSection,
__in DWORD dwSpinCount
);
Parameters
lpCriticalSection [in, 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 zero (0). On multiprocessor systems, if the critical section is unavailable, the calling thread spins 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.
Return Value
The function returns the previous spin count for the critical section.
Remarks
The threads of a single process can use a critical section object for mutual-exclusion synchronization. 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 call the InitializeCriticalSection or InitializeCriticalSectionAndSpinCount function to initialize the object. You can subsequently modify the spin count by calling the SetCriticalSectionSpinCount function.
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.
To compile an application that uses this function, define _WIN32_WINNT as 0x0403 or later. For more information, see Using the Windows Headers .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
Critical Section Objects
InitializeCriticalSection
InitializeCriticalSectionAndSpinCount
Synchronization Functions
WaitForSingleObject
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms686197(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:18:40