当前位置:网站首页>线程同步的基石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
边栏推荐
- How to configure the national standard platform easygbs neutral version?
- Opencv learning notes - loading and saving images
- QT -- the qtabwidget supports dragging tabbar items
- A scheme for crawlers to collect public opinion data
- 105. simple chat room 8: use socket to transfer pictures
- Continuous testing | making testing more free: practicing automated execution of use cases in coding
- Smart Policing: how to use video intelligent analysis technology to help urban policing visual comprehensive supervision and command system
- Cryptography series: collision defense and collision attack
- Smart photovoltaic energy - visualization of photovoltaic power generation energy management and control in the park
- Tencent cloud and the ICT Institute launched the preparation of the "cloud native open source white paper" to deeply interpret cloud native
猜你喜欢
[mysql_16] variables, process control and cursors

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

QT -- the qtabwidget supports dragging tabbar items

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

Opencv learning notes - loading and saving images

Dingding, Feishu, and enterprise wechat: different business approaches

《回归故里》阅读笔记

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

钉钉、飞书、企业微信:迥异的商业门道

Babbitt | metauniverse daily must read: 618 scores have been announced. How much contribution has the digital collection made behind this satisfactory answer
随机推荐
Data stack technology sharing: open source · data stack - extend flinksql to realize the join of flow and dimension tables
The solution of distributed system: directory, message queue, transaction system and others
105. 简易聊天室8:使用 Socket 传递图片
How to do research on plant endophytes? Special topic on Microbiology
Go basic series | 1 Leading
Can Tencent's tendis take the place of redis?
Easynvr user login is modified to share the modification process of ip+ user name restriction
[cloud based co creation] interpretation of harmonyos application and service ecology
Making daily menu applet with micro build low code
[highlights] summary of award-winning activities of Tencent cloud documents
Istio practical skills: using prism to construct multi version test services
On the value foam of digital copyright works from the controversial nature of "Meng Hua Lu"
Practice of dynamic load balancing based on open source tars
Deep parsing and implementation of redis pub/sub publish subscribe mode message queue
How to check the situation that the national standard platform easygbs equipment video cannot be accessed by grabbing packets?
Istio FAQ: istio init crash
[day ui] alert component learning
SMS SMS
Pipeline post instruction
mLife Forum | 微生物组和数据挖掘