当前位置:网站首页>MFC多线程 信号量CSemaphore 临界区与互斥 事件
MFC多线程 信号量CSemaphore 临界区与互斥 事件
2022-06-24 06:41:00 【小黄人软件】
CMutex, CCriticalSection用于对资源的互斥访问。
CMutex可以跨进程使用, CCriticalSection只可以在进程内部使用。
创建CMutex需要更多的资源,只用于进程内部时使用CCriticalSection获得更高的效率。
CCriticalSection m_CritSection;//用于临界区 方法一
CSingleLock singleLock(&m_CritSection); //
//CMutex Mutex;//用于互斥锁 方法二
//CSingleLock singleLock(&Mutex); //
int StartMainLock()
{
singleLock.Lock();//没被调用就上锁自己用,已被调用就等着
if (singleLock.IsLocked())
{
int ret=StartMain(); //被锁的 处理内容
singleLock.Unlock();//解锁 所有返回之前解锁
return ret;
}
singleLock.Unlock();//解锁
return -1;
}
//事件
HANDLE m_hEvent= CreateEvent(NULL, FALSE, FALSE, NULL); //新建
WaitForSingleObject(m_hEvent, INFINITE); //无限时间等待
ResetEvent(m_hEvent); 重置 为无信号
SetEvent(m_hEvent); //设置有信号
CloseHandle(m_hEvent); //关闭CSemaphore指定资源的线程的计数
边栏推荐
- Introduction to raspberry pie 4B development board
- High energy ahead: Figure 18 shows you how to use the waterfall chart to visually reflect data changes
- JVM调试工具-jmap
- Thread safety and its implementation
- LuChen technology was invited to join NVIDIA startup acceleration program
- Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.
- 原神方石机关解密
- 1. go deep into tidb: see tidb for the first time
- How to operate the little red book account: making good use of the theory of long tail words
- Spark accumulators and broadcast variables
猜你喜欢

Canal安装配置

leetcode:1856. Maximum value of minimum product of subarray

Spark project Packaging Optimization Practice

Introduction to raspberry pie 4B development board

Challenges brought by maker education to teacher development

Functions in setinterval cannot have parentheses

JVM调试工具-jvisualvm

大厂不是衡量能力的唯一出路,上财学姐毕业三年的经验分享

leetcode:85. Max rectangle

智能视觉组A4纸识别样例
随机推荐
开源与创新
How to register the cloud service platform and what are the advantages of cloud server
A case study of apiserver avalanche caused by serviceaccount
Development of IOT device end - establishment of development environment
Record the problem location experience when an application is suddenly killed
[security] how to [host security - hybrid cloud version] support secure access to non Tencent virtual machines
On update current in MySQL_ TIMESTAMP
Typora charges? Build vs Code markdown writing environment
Spark accumulators and broadcast variables
[problem solving] virtual machine configuration static IP
c#:互斥锁的使用
One year since joining Tencent
High energy ahead: Figure 18 shows you how to use the waterfall chart to visually reflect data changes
毕业季进击的技术
Spark累加器和廣播變量
虚拟文件系统
浅谈如何运营好小红书账号:利用好长尾词理论
Typora收费?搭建VS Code MarkDown写作环境
decade
Overview of cloud computing advantages of using cloud computing