CCriticalSection 有什么作用? [英] What does CCriticalSection do?

查看:41
本文介绍了CCriticalSection 有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码有什么区别:

::EnterCriticalSection( &m_CriticalSection );
//...
::LeaveCriticalSection( &m_CriticalSection );

和代码:

static CCriticalSection cs;
cs.Lock();
//...
cs.UnLock();

推荐答案

实际上没有区别.CCriticalSection 是前者唯一的语法糖.它内部使用EnterCriticalSectionLeaveCriticalSection!

No difference practically. CCriticalSection is the only syntatic sugar of the former. It internally uses EnterCriticalSection and LeaveCriticalSection!

EnterCriticalSectionLeaveCriticalSection 是低级的 win32 API,而 CCriticalSection 是包装这些功能的 MFC 类.它具有 API 使用的 CRITICAL_SECTION 类型的成员数据.

EnterCriticalSection and LeaveCriticalSection are low-level win32 APIs, while CCriticalSection is a MFC class which wraps these functionalities. It has a member data of type CRITICAL_SECTION which is used by the APIs.

MSDN 说,

功能CCriticalSection 类由实际的 Win32 CRITICAL_SECTION对象.

The functionality of the CCriticalSection class is provided by an actual Win32 CRITICAL_SECTION object.

这篇关于CCriticalSection 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆