当前位置:网站首页>内核同步机制
内核同步机制
2022-07-01 11:19:00 【每日一悟】
关于同步理论的一些基本概念:
临界区(critical area): 访问或操作共享数据的代码段,可以简单理解为synchronized大括号中部分(原子性)竞争条件(race conditions):两个线程同时拥有临界区的执行权
数据不一致:data unconsistency 由竞争条件引起的数据破坏
同步(synchronization):避免race conditions
锁:完成同步的手段(门锁,门后是临界区,只允许一个线程存在) 上锁解锁必须具备原子性
原子性:像原子一样不可分割的操作
有序性:禁止指令重排
可见性:一个线程内的修改,另一个线程可见
内核同步常用方法:
- 原子操作:内核中类似于AtomicXXX,位于<linux/types.h>
- 自旋锁:内核中通过汇编支持的cas,位于<asm/spinlock.h>
- 读写自旋:类似于ReadWriteLock,可同时读,只能一个写,读的时候是共享锁,写的时候是排他锁
- 信号量:类似于Semaphore(PV操作down up操作,占有和释放) 重量级锁,线程会进入wait,适合长时间持有的锁情况
- 读写信号量:downread upread downwrite upwrite (多个写,可以分段写,比较少用)(分段锁)
- 互斥体(mutex):特殊的信号量(二值信号量)
- 完成变量:特殊的信号量(A发出信号给B,B等待在完成变量上) vfork() 在子进程结束时通过完成变量叫醒父进程 类似于(Latch)
- BKL:大内核锁
- 顺序锁(2.6):线程可以挂起的读写自旋锁,序列计数器(从0开始,写时增加(+1),写完释放(+1),读前发现单数, 说明有写线程,等待,读前读后序列一样,说明没有写线程打断)
- 禁止抢占:preempt_disable()
- 内存屏障 :见volatile
边栏推荐
- Tempest HDMI leak reception 4
- Network security learning notes 01 network security foundation
- CVPR22 |CMT:CNN和Transformer的高效结合(开源)
- MIT's latest paper, "the need for interpretable features: motivation and classification": building interpretability in the constituent elements of machine learning models
- CANN算子:利用迭代器高效实现Tensor数据切割分块处理
- 8款最佳实践,保护你的 IaC 安全!
- Google's new paper Minerva: solving quantitative reasoning problems with language models
- Intel Labs announces new progress in integrated photonics research
- CPI教程-异步接口创建及使用
- 证券账户随便哪里开都能使用吗 开户安全吗
猜你喜欢
Network security learning notes 01 network security foundation
【MAUI】为 Label、Image 等控件添加点击事件
Skip the test cases to be executed in the unittest framework
Intel Labs annonce de nouveaux progrès en photonique intégrée
Value 1000 graduation project campus information publishing platform website source code
CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
華為設備配置大型網絡WLAN基本業務
Unittest 框架介绍及第一个demo
TEMPEST HDMI泄漏接收 4
技术分享 | Linkis参数介绍
随机推荐
Oracle和JSON的结合
获取键代码
技术分享 | Linkis参数介绍
软件项目管理 9.2.软件项目配置管理过程
Google's new paper Minerva: solving quantitative reasoning problems with language models
Introduction to unittest framework and the first demo
applyMiddleware 原理
“目标检测”+“视觉理解”实现对输入图像的理解及翻译(附源代码)
The idea runs with an error command line is too long Shorten command line for...
我国蜂窝物联网用户已达 15.9 亿,年内有望超越移动电话用户
流动性质押挖矿系统开发如何制作,dapp丨defi丨nft丨lp流动性质押挖矿系统开发案例分析及源码
When is testing not unit testing- When is a Test not a Unit-test?
CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
No statements may be issued when any streaming result sets are open and in use on a given connection
Openinstall: wechat applet jump to H5 configuration service domain name tutorial
MIT最新论文《对可解释特征的需求:动机和分类》:在机器学习模型的组成元素中建立可解释性
名创拟7月13日上市:最高发行价22.1港元 单季净利下降19%
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
Matrix of numpy
Technology sharing | introduction to linkis parameters