InitializeCriticalSection函数理解

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.

 

此是本人根据自己的体会翻译而来,所有由于本人水平有限,如果有错误的地方,请谅解并欢迎指正。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值