网站首页  词典首页

请输入您要查询的函数:

 

术语 tryentercriticalsection
释义 TryEnterCriticalSection
语法:
C++
BOOL WINAPI TryEnterCriticalSection(
__inout LPCRITICAL_SECTION lpCriticalSection
);
TryEnterCriticalSection功能
没有试图阻止进入一个关键部分。如果调用成功,则调用线程注意到临界区的所有权。
参数
lpCriticalSection [ in , out ]
一个临界区对象的指针。
返回值
如果临界区成功地进入或者当前线程已经拥有的关键部分,返回非零值。
如果另一个线程已经拥有临界区,返回值是零。
备注
单个进程的线程可以使用一个互斥同步临界区对象。这个过程负责分配一个关键节对象,它可以通过声明类型的CRITICAL_SECTION的变量使用的内存。之前使用一个关键部分,一些进程中的线程必须调用InitializeCriticalSection或InitializeCriticalSectionAndSpinCount函数来初始化对象。
为使相互排斥的共享资源的使用,每个线程调用加锁或TryEnterCriticalSection功能要求在执行代码的任何部分,使用资源的保护临界区的所有权。不同的是,TryEnterCriticalSection立即返回,无论是否获得了临界区的所有权,而加锁块,直到线程可以利用临界区的所有权。当它已经完成了受保护的代码执行的线程使用LeaveCriticalSection放弃所有权的功能,使另一个线程来成为业主,并获得受保护资源。该线程必须要求每次LeaveCriticalSection一旦它进入临界区。
任何进程中的线程可以使用DeleteCriticalSection函数来释放分配制度时,关键节对象初始化的资源。在此之后的功能被称为临界区对象不能用于同步。
如果一个线程终止,同时它有一个关键部分所有权,临界区状态是不确定的。
要编译的应用程序使用此功能,定义_WIN32_WINNT为0x0400或更高版本。有关详细信息,请参阅使用Windows头。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
临界区对象
DeleteCriticalSection
加锁
InitializeCriticalSection
InitializeCriticalSectionAndSpinCount
LeaveCriticalSection
同步功能
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==TryEnterCriticalSection Function
Attempts to enter a critical section without blocking. If the call is successful, the calling thread takes ownership of the critical section.
Syntax
C++
BOOL WINAPI TryEnterCriticalSection(
__inout LPCRITICAL_SECTION lpCriticalSection
);
Parameters
lpCriticalSection [in, out]
A pointer to the critical section object.
Return Value
If the critical section is successfully entered or the current thread already owns the critical section, the return value is nonzero.
If another thread already owns the critical section, the return value is zero.
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.
To enable mutually exclusive use of a shared resource, each thread calls the EnterCriticalSection or TryEnterCriticalSection function to request ownership of the critical section before executing any section of code that uses the protected resource. The difference is that TryEnterCriticalSection returns immediately, regardless of whether it obtained ownership of the critical section, while EnterCriticalSection blocks until the thread can take ownership of the critical section. When it has finished executing the protected code, the thread uses the LeaveCriticalSection function to relinquish ownership, enabling another thread to become the owner and gain access to the protected resource. The thread must call LeaveCriticalSection once for each time that it entered the critical section.
Any thread of the process can use the DeleteCriticalSection function to release the system resources that were allocated when the critical section object was initialized. After this function has been called, the critical section object can no longer be used for synchronization.
If a thread terminates while it has ownership of a critical section, the state of the critical section is undefined.
To compile an application that uses this function, define _WIN32_WINNT as 0x0400 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
DeleteCriticalSection
EnterCriticalSection
InitializeCriticalSection
InitializeCriticalSectionAndSpinCount
LeaveCriticalSection
Synchronization Functions
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms686857(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:21