当前位置:网站首页>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状态。
边栏推荐
- MapReduce elementary programming practice
- SPuG - lightweight automatic operation and maintenance platform
- 攻击队攻击方式复盘总结
- What are cookies and the security risks of v-htm
- What is digitalization? What is digital transformation? Why do enterprises choose digital transformation?
- What are the requirements for customizing the slip ring for UAV
- Is there any risk in opening an account for flush stock? Is it safe for flush to open an account
- Deep parsing of kubernetes controller runtime
- Ten thousand words long article understanding business intelligence (BI) | recommended collection
- How to build dual channel memory for Lenovo Savior r720
猜你喜欢

什麼是數字化?什麼是數字化轉型?為什麼企業選擇數字化轉型?

为什么要选择不锈钢旋转接头

MapReduce elementary programming practice

What is the application scope and function of the conductive slip ring of single crystal furnace

零基礎多圖詳解圖神經網絡

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

单晶炉导电滑环的应用范围和作用是什么

什么是过孔式导电滑环?

SQL Server 2016 detailed installation tutorial (with registration code and resources)

Proe/creo product structure design - continuous research
随机推荐
Every time I started the service of the project, the computer helped me open the browser, revealing the 100 lines of source code!
为什么要选择不锈钢旋转接头
Is the stock investment exchange group safe? Is it reliable to open an account for free?
What is a better and safer app for securities companies to buy stocks
How to understand query, key and value in transformer
electron窗口背景透明无边框(可用于启动页面)
Is there any risk in opening an account for flush stock? Is it safe for flush to open an account
电商转化率这么抽象,到底是个啥?
药物发现综述-01-药物发现概述
How to build dual channel memory for Lenovo Savior r720
Why are cloud vendors targeting this KPI?
Want to open an account to buy stock, is it safe to open an account on the Internet?
Official announcement! Apache Doris graduated from the Apache incubator and officially became the top project of Apache!
去哪儿网(Qunar) DevOps 实践分享
Golang monkeys eat peaches and ask for the number of peaches on the first day
Is it safe for Xiaobai in the stock market to open an account on the Internet?
Latest MySQL advanced SQL statement Encyclopedia
Cloud assisted privacy collection intersection (server assisted psi) protocol introduction: Learning
药物发现综述-02-分子性质预测
MySQL - function