当前位置:网站首页>C: use of mutex
C: use of mutex
2022-06-24 07:02:00 【Machine vision 001】
1. The mutex lock
Definition :
private static readonly object m_objLock = new object();
Use :
lock (m_objLock)
{
// todo
}
effect : Will lock the contents of the code block , And prevent other threads from entering the code block , Until the code block is completed , Release the lock .Be careful : The defined lock object should be : private + static state + read-only + Object of reference type , This prevents external changes to the lock object .
2. The mutex Monitor
Definition :
private static readonly object m_objLock = new object();
Use :
Monitor.Enter(m_objLock);
//todo
Monitor.Exit(m_objLock);
effect : Will lock the contents of the code block , And prevent other threads from entering the code block , Until the code block is completed , Release the lock .Be careful : Be careful : The defined lock object should be : private + static state + read-only + Object of reference type , This prevents external changes to the lock object .
Monitor Yes TryEnter The function of , It can prevent deadlock problems ,lock No, .
3. The mutex Mutex
Definition :
private static readonly Mutex mutex = new Mutex();
Use :
mutex.WaitOne();
//todo
mutex.ReleaseMutex();
effect : Will lock the contents of the code block , And prevent other threads from entering the code block , Until the code block is completed , Release the lock .Be careful : Be careful : The defined lock object should be : private + static state + read-only + Object of reference type , This prevents external changes to the lock object .
Mutex It can be system level , So it can span the process .
边栏推荐
- RS485 serial port wiring description of smart lamp post smart gateway
- Do you want to research programming? I got six!
- C语言学生管理系统——可检查用户输入合法性,双向带头循环链表
- 数据库 存储过程 begin end
- Deploy DNS server using dnsmasq
- 35 year old crisis? It has become a synonym for programmers
- sql join的使用
- decade
- 智能视觉组A4纸识别样例
- NVIDIA control panel does not open what is NVIDIA control panel
猜你喜欢

oracle sql综合运用 习题

程序员使用个性壁纸

Maui uses Masa blazor component library

华为云低时延技术的九大绝招

Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures

leetcode:剑指 Offer 26:判断t1中是否含有t2的全部拓扑结构

leetcode:85. Max rectangle

成为 TD Hero,做用技术改变世界的超级英雄 | 来自 TDengine 社区的邀请函

Interpreting top-level design of AI robot industry development

潞晨科技获邀加入NVIDIA初创加速计划
随机推荐
Nine unique skills of Huawei cloud low latency Technology
Spark累加器和广播变量
[binary number learning] - Introduction to trees
云上本地化运营,东非第一大电商平台Kilimall的出海经
What is domain name resolution? What if the domain name cannot be resolved?
Code scanning | a sharp tool for controlling code quality
[binary tree] - middle order traversal of binary tree
Internet cafe management system and database
JSON formatting method advantages of JSON over XML
缓存操作rockscache原理图
【二叉树】——二叉树中序遍历
What is the main function of cloud disk? How to restore deleted pictures
潞晨科技获邀加入NVIDIA初创加速计划
leetcode:1856. Maximum value of minimum product of subarray
Go operation SQLite code error
setInterval里面的函数不能有括号
Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.
[5 minutes to play lighthouse] take you to the light kubernetes release k3s
智能视觉组A4纸识别样例
leetcode:85. Max rectangle