当前位置:网站首页>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 .
边栏推荐
- Leetcode: Sword finger offer 26: judge whether T1 contains all topologies of T2
- 【问题解决】虚拟机配置静态ip
- Centos7 deploying mysql-5.7
- Interpreting top-level design of AI robot industry development
- 记录--关于JSP前台传参数到后台出现乱码的问题
- How to make a website? What should I pay attention to when making a website?
- Do you want to research programming? I got six!
- 文件系统笔记
- MAUI使用Masa blazor组件库
- Domain name purchase method good domain name selection principle
猜你喜欢

35岁危机?内卷成程序员代名词了
![[JUC series] completionfuture of executor framework](/img/d0/c26c9b85d1c1b0da4f1a6acc6d33e3.png)
[JUC series] completionfuture of executor framework

The data synchronization tool dataX has officially supported reading and writing tdengine

MAUI使用Masa blazor组件库

记录--关于virtual studio2017添加报表控件的方法--Reportview控件

Record -- about the problem of garbled code when JSP foreground passes parameters to the background

Localized operation on cloud, the sea going experience of kilimall, the largest e-commerce platform in East Africa

Spark项目打包优化实践

puzzle(019.1)Hook、Gear
![Jumping game ii[greedy practice]](/img/e4/f59bb1f5137495ea357462100e2b38.png)
Jumping game ii[greedy practice]
随机推荐
How to make a website? What should I pay attention to when making a website?
On BOM and DOM (3): DOM node operation - element style modification and DOM content addition, deletion, modification and query
程序员使用个性壁纸
Go breakpoint continuation
Le système de surveillance du nuage hertzbeat v1.1.0 a été publié, une commande pour démarrer le voyage de surveillance!
Arduino融资3200万美元,进军企业市场
Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.
Thread safety and its implementation
成为 TD Hero,做用技术改变世界的超级英雄 | 来自 TDengine 社区的邀请函
Do you want to research programming? I got six!
How to register the cloud service platform and what are the advantages of cloud server
学生管理系统页面跳转及数据库连接
Deploy DNS server using dnsmasq
数据库 存储过程 begin end
文件系统笔记
. Net7 miniapi (special part):preview5 optimizes JWT verification (Part 1)
Centos7 deploying mysql-5.7
Application configuration management, basic principle analysis
【愚公系列】2022年6月 ASP.NET Core下CellReport报表工具基本介绍和使用
Easy car Interviewer: talk about MySQL memory structure, index, cluster and underlying principle!