This function initializes a critical section object.
此函数初始化一个临界区对象。
格式:
void InitializeCriticalSection(
LPCRITICAL_SECTION lpCriticalSection
);
Parameters
lpCriticalSection
[in] Pointer to the critical section object.
参数:
lpCriticalSection[in]指向临界区对象的指针。
Return Values
None.
返回值:None
Remarks
The threads of a single process can use a critical section object for mutual-exclusion synchronization. Although there is no guarantee about the order in which threads will obtain ownership of the critical section, the system will process ownership requests from 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 call the InitializeCriticalSection function to initialize the object.
Once a critical section object has been initialized, the threads of the process can specify the object in the EnterCriticalSection 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 provided by the Microsoft Win32® API to manage critical section objects.
In low-memory situations, InitializeCriticalSection can raise a STATUS_NO_MEMORY exception.
备注:
单个进程的线程可以使用一个互斥同步临界区对象。虽然对线程将获得临界区所有权的顺序没有保证,该系统将处理所有线程的所有权要求。
这个进程负责分配一个临界区对象使用的内存,它可以通过声明类型的CRITICAL_SECTION的变量使用的内存。在使用一个临界区对象以前,一些进程中的线程必须调用InitializeCriticalSection函数来初始化对象。
一旦一个临界区对象已被初始化,该进程的线程可以在EnterCriticalSection或LeaveCriticalSection函数指定对象,提供对共享资源的相互独占式访问。对于不同进程之间的类似线程同步,使用互斥对象。
一个临界区对象不能移动或复制。这一进程也绝不能修改该对象,但必须把它作为逻辑不透明来处理。只能使用由与Microsoft Win32 ® API提供的临界区功能,用来管理临界区对象。
在低内存的情况下,InitializeCriticalSection可能提出STATUS_NO_MEMORY异常。
Requirements
OS Versions: Windows CE 1.0 and later.
Header: Winbase.h.
Link Library: Coremain.lib.
此是本人根据自己的体会翻译而来,所有由于本人水平有限,如果有错误的地方,请谅解并欢迎指正。