当前位置:网站首页>PV操作原语
PV操作原语
2022-06-27 23:11:00 【AdamShyly】
"原子操作(atomic operation)是不需要synchronized",这是多线程编程的老生常谈了。所谓原子操作是指不会被线程调度机制打断的操作;这种操作一旦开始,就一直运行到结束,中间不会有任何 context switch [1] (切换到另一个线程)。
原子操作大部分使用汇编语言实现,因为c语言并不能实现这样的操作。
原子性不可能由软件单独保证--必须需要硬件的支持,因此是和架构相关的。在x86 平台上,CPU提供了在指令执行期间对总线加锁的手段。CPU芯片上有一条引线#HLOCK pin,如果汇编语言的程序中在一条指令前面加上前缀"LOCK",经过汇编以后的机器代码就使CPU在执行这条指令的时候把#HLOCK pin的电位拉低,持续到这条指令结束时放开,从而把总线锁住,这样同一总线上别的CPU就暂时不能通过总线访问内存了,保证了这条指令在多处理器环境中的原子性。
——摘自百度百科
而操作系统中之所以通过PV操作来访问信号量可以用来实现进程互斥同步,也是因为PV原语是不可中断的,是原子操作。根据上方百度百科对原子操作的介绍可知,在单处理器模式下,当多个进程并发访问临界资源时,P操作原语可以将最先执行到该原语代码的进程置于不可中断的状态,此时其他并发进程由于不能通过CPU将该进程中断而进行抢占CPU资源,从而进入block状态,等到该进程执行v操作原语后,唤醒其中一个阻塞进程恢复成ready状态。
边栏推荐
- How to understand query, key and value in transformer
- 同花顺股票开户是会有什么风险吗?同花顺开户安全吗
- Leetcode 720. The longest word in the dictionary
- Interface component telerik UI for WPF Getting Started Guide - how to switch custom styles using themes
- 网页鼠标点击特效案例收集(直播间红心同理)
- Overview and deployment of GFS distributed file system
- Proe/Creo产品结构设计-钻研不断
- Ten MySQL locks, one article will give you full analysis
- Modular development
- Solon 1.8.3 发布,云原生微服务开发框架
猜你喜欢

Ten thousand words long article understanding business intelligence (BI) | recommended collection

药物发现综述-02-分子性质预测

Electron window background transparent borderless (can be used to start the page)

Taro--- day2--- compile and run

Introduction to memory model of JVM

Huawei partners and Developers Conference 2022 | Kirin software cooperates with Huawei to jointly build the computing industry and create a digital intelligence future

SPuG - lightweight automatic operation and maintenance platform

DeepMind | 通过去噪来进行分子性质预测的预训练

How to understand query, key and value in transformer

Meituan dynamic thread pool practice idea has been open source
随机推荐
药物发现综述-01-药物发现概述
Ai+ clinical trial patient recruitment | massive bio completed round a financing of $9million
#795 Div.2 E. Number of Groups set *
电商转化率这么抽象,到底是个啥?
awk注意的几个问题
基于可学习尺寸自适应分子亚结构的药物相互作用预测
Cloud native O & M article plan
Redis configuration and optimization of NoSQL
Huawei partners and Developers Conference 2022 | Kirin software cooperates with Huawei to jointly build the computing industry and create a digital intelligence future
大尺寸导电滑环市场应用强度如何
Import the data table in MySQL into Excel
什么是过孔式导电滑环?
【说明】Jmeter乱码的解决方法
免费、好用、强大的开源笔记软件综合评测
现在炒股网上开户安全吗?新手刚上路,求答案
Is it reliable to invest in exchange traded ETF funds? Is it safe to invest in exchange traded ETF funds
Ten MySQL locks, one article will give you full analysis
What is a through-hole conductive slip ring?
Is it safe to open an account for mobile stocks? Where can I open an account for buying stocks?
吸顶方案1