当前位置:网站首页>C thread lock
C thread lock
2022-07-27 06:07:00 【The moonlight is shining】
C# Thread lock (Lock)
Lock The role of
Lock It can be seen as a critical area in the operating system ,Lock The code in the area represents the critical area , Only one thread can enter at the same time Lock Included functions , Atomic operation , To protect the same resource, only one thread can modify , Realize the synchronization of data in different threads .
Not in Lock The thread of will be blocked waiting , until Lock Only when the lock is opened can one of them wake up to enter , And lock it
Lock Use
private Object thisLock = new Object();// Create object lock
lock (thisLock)
{
// Critical code section
}
Lock Precautions for use
1、 Note that the object lock created first , It should be the same object that different threads can access , So at least it should be global in the class , Should not be a local variable .
2、 To achieve global object locking , have access to static, example :
private static Object thisLock = new Object();// Create object lock
3、 Combined with the running characteristics of their own threads , Choose the right object lock
边栏推荐
- Leetcode每日一题30. 串联所有单词的子串
- [first song] machine learning of rebirth - linear regression
- When multiple formulas in latex share a sequence number
- [Arduino] reborn Arduino monk (1)
- 人月神话阅读笔记
- Day 2. Depressive symptoms, post-traumatic stress symptoms and suicide risk among graduate students
- 编程学习记录——第9课【操作符】
- 【头歌】重生之我在py入门实训中(4):循环程序
- 2021-06-26
- Kaggle调用自定义模块方法
猜你喜欢

非真实感渲染(NPR)论文理解及其复现(Unity) - 《Stylized Highlights for Cartoon Rendering and Animation》

When multiple formulas in latex share a sequence number

C# Json编码在TCP通讯中的一些使用总结

韦东山 数码相框 项目学习(四)简易的TXT文档显示器(电纸书)

Greedy high performance neural network and AI chip application research and training
Acwing the number of square arrays of one question per day
![[first song] machine learning of rebirth - linear regression](/img/70/3efd9eacf88f55022eb52d096926f7.png)
[first song] machine learning of rebirth - linear regression

一张图看懂指针

Super remote connection management tool: Royal TSX

Unity 窗口界面的简单介绍
随机推荐
Baiwen driver Daquan learning (I) LCD driver
根据SQL必知必会学习SQL(MYSQL)
Socket programming 1: using fork() to realize the most basic concurrency mode
[first song] rebirth of me in py introductory training (4): Circular program
编程学习记录——第9课【操作符】
C语言-文件操作
C语言-自定义结构类型
力扣题解 动态规划(5)
数据库索引的一些说明以及使用
编程学习记录——第7课【函数】
Unity 实用小技巧(更新ing)
[Arduino] reborn Arduino monk (1)
【头歌】重生之我在py入门实训中(4):循环程序
论文写作(收获)
Gbase 8C - SQL reference 6 SQL syntax (12)
[5.20 special] MATLAB, I'm confessing to you
STM32 infrared remote control
c语言-线性顺序表
Dpdk network protocol stack VPP OVS DDoS Sdn nfv virtualization high performance expert Road
[first song] rebirth of me in py introductory training (6): definition and application of functions