当前位置:网站首页>内核同步机制
内核同步机制
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
边栏推荐
- Skip the test cases to be executed in the unittest framework
- Intel Labs annonce de nouveaux progrès en photonique intégrée
- Width and widthstep of iplimage
- 分享psd格式怎么预览的方法和psd文件缩略图插件[通俗易懂]
- Development overview of fund internationalization
- Cvpr22 | CMT: efficient combination of CNN and transformer (open source)
- MIT最新论文《对可解释特征的需求:动机和分类》:在机器学习模型的组成元素中建立可解释性
- The developer said, "this doesn't need to be tested, just return to the normal process". What about the testers?
- Flip the array gracefully
- Matrix of numpy
猜你喜欢

applyMiddleware 原理

英特尔实验室公布集成光子学研究新进展

kubernetes之ingress探索实践

Unittest 框架介绍及第一个demo

Cvpr22 | CMT: efficient combination of CNN and transformer (open source)

Network security learning notes 01 network security foundation

Face detection and recognition system based on mtcnn+facenet

Node version manager NVM installation and switching

我国蜂窝物联网用户已达 15.9 亿,年内有望超越移动电话用户

Oracle和JSON的结合
随机推荐
金鱼哥RHCA回忆录:DO447使用Ansible与API通信--使用Ansible Tower API启动作业
Development overview of fund internationalization
The idea runs with an error command line is too long Shorten command line for...
In June 2022, it was the first programming language?!
Graduation season · advanced technology er
Harbor webhook从原理到构建
tmux使用
Test case writing specification in unittest framework and how to run test cases
Ten years of sharpening a sword: unveiling the secrets of ant group's observability platform antmonitor
放弃深圳高薪工作回老家
CVPR 2022 | 基于密度与深度分解的自增强非成对图像去雾
Win平台下influxDB导出、导入
Matrix of numpy
華為設備配置大型網絡WLAN基本業務
技术分享 | Linkis参数介绍
Oracle和JSON的结合
关于Keil编译程序出现“File has been changed outside the editor,reload?”的解决方法
微信小程序开发 – 用户授权登陆「建议收藏」
Unittest 框架介绍及第一个demo
Tempest HDMI leak reception 4