当前位置:网站首页>线程同步的基石AbstractQueuedSynchronizer详解
线程同步的基石AbstractQueuedSynchronizer详解
2022-06-24 12:33:00 【jerry_dyy】
概述:
AQS定义了多个线程访问共享资源的同步器框架,通过CLH队列来实现线程同步的一个框架:

结合上图里面的CLH队列,当多个线程都来访问同一个资源:state时,每一个线程都会创建一个对应的节点放到队列里面去。线程1第一个进入,head便指向了线程1创建的节点1,那么节点1就拥有对资源的访问权,而后面进入的线程创建的节点依次放入CLH队列尾部,线程都进入等待状态。当head节点里的线程1对资源访问完毕之后,线程1唤醒后面的线程2,线程2将head指向线程2所在节点2,此时节点1就出队列了,线程2此时拥有对资源的访问权,以此类推。
其中state是多个线程都要去竞争的资源,state是AbstarctQueuedSynchronizer里的一个被volatile修饰的类型为int的成员变量,关于state的操作,也就是关于资源的操作,都是在tryXx
边栏推荐
- 《回归故里》阅读笔记
- A hero's note stirred up a thousand waves across 10 countries, and the first-line big factories sent people here- Gwei 2022 Singapore
- Tsingsee green rhino video "cloud side end" +ai intelligent security system is integrated into the mainstream development trend
- Tencent Youtu, together with Tencent security Tianyu and wechat, jointly launched an infringement protection scheme
- Ghost, a synonym for blog system
- Making daily menu applet with micro build low code
- Kubernetes practical skill: entering container netns
- 从《梦华录》的争议性,谈谈数字版权作品的价值泡沫
- Babbitt | metauniverse daily must read: 618 scores have been announced. How much contribution has the digital collection made behind this satisfactory answer
- Smart Policing: how to use video intelligent analysis technology to help urban policing visual comprehensive supervision and command system
猜你喜欢
![[database] final review (planning Edition)](/img/94/cd2df3a011c4e466df5aaa0f3bd0f2.png)
[database] final review (planning Edition)

解析nc格式文件,GRB格式文件的依赖包edu.ucar.netcdfAll的api 学习

微医CodeReview工具链

《回归故里》阅读笔记

一文讲透植物内生菌研究怎么做 | 微生物专题

A hero's note stirred up a thousand waves across 10 countries, and the first-line big factories sent people here- Gwei 2022 Singapore

使用开源工具 k8tz 优雅设置 Kubernetes Pod 时区
[mysql_16] variables, process control and cursors

【概率论期末抱佛脚】概念+公式(不含参数估计)

Use the open source tool k8tz to gracefully set the kubernetes pod time zone
随机推荐
National standard platform easygbs administrator assigns roles to sub users and troubleshooting of invalid channels
Tencent security monthly report - zero trust development trend forum, digital Expo Technology Award, Mercedes Benz security research results
Listed JD Logistics: breaking through again
从《梦华录》的争议性,谈谈数字版权作品的价值泡沫
Istio Troubleshooting: uneven grpc service load
About me, a 19 line programmer
Process of solving easydss virtual live video jam and instability problems by replacing push-pull stream Library
Go basic series | 1 Leading
Istio FAQ: istio init crash
A "full cloud" journey of a quasi financial system
[mysql_16] variables, process control and cursors
Concept + formula (excluding parameter estimation)
Reset the password, and the automatic login of the website saved by chrome Google browser is lost. What is the underlying reason?
Use the object selection tool to quickly create a selection in Adobe Photoshop
How can a shell script (.Sh file) not automatically close or flash back after execution?
Interesting erasure code
pipeline groovy
How does easygbs, a national standard platform, solve the problem that information cannot be carried across domains?
How do websites and we media tap user needs? Deeply expose the secrets behind the keywords!
Making daily menu applet with micro build low code