当前位置:网站首页>Cyclicbarrier and countdownlatch [concurrent programming]
Cyclicbarrier and countdownlatch [concurrent programming]
2022-07-24 09:39:00 【liuyunshengsir】
1.CyclicBarrier A brief overview of
CyclicBarrier It is a synchronization tool class for multiple threads waiting for each other to reach a common barrier point , Here's the picture , Xiao Ming , Xiaobao , Xiao Zhou needs to wait for others to reach the public barrier point , To continue to do other things , It is often used for tasks that need to be completed by multiple threads . The essence is through Lock, Control one state state , Atomic update to 0.
CyclicBarrier Literally means “ Reusable fence ”,CyclicBarrier comparison CountDownLatch Come on , It's a lot easier , Its source code does not have what deep place , It is ReentrantLock and Condition Combined use of .
CyclicBarrier and CountDownLatch Is it very similar , It's just CyclicBarrier There can be more than one fence , Because of its fence (Barrier) Can be reused (Cyclic).
2.CyclicBarrier Two scenarios used
1、n Threads have prepared some data , And then call await Method , The main thread is handled by them , It can be summed up n Data prepared by threads .
2、n All threads are waiting , One by one ,await The method is equivalent to checking in , Every thread calls await Sign in first , Wait until the number of barriers equals 0, Then deal with the following logic , The thread that finally signed in executes the barrier and wakes up other waiting threads .
3.CyclicBarrier And CountDownLatch difference
1、CyclicBarrier Can be reset , and CountDownLatch Cannot reset .
2、CountDownLatch Is the count of one or more threads reduced to 0, Start doing things together .CyclicBarrier Is the last thread , Wake up other counter is 0 The thread of , Start doing things .
3、CyclicBarrier It's based on exclusive locks ReentrantLock Exclusive lock implementation ,CountDownLatch It is based on shared lock .
边栏推荐
- CUDA day 2: GPU core and Sm core components [easy to understand]
- One year after I came to Ali, I ushered in my first job change
- Tang Yudi opencv background modeling
- 代码随想录笔记_链表_25K个一组翻转链表
- Gnuplot software learning notes
- Ansible 常用模块介绍
- 分类与回归的区别
- Boundless dialogue | participate in the live broadcast on July 25 and win the prize
- SDUT compilation principle experimental code
- Spark Learning: Spark implementation of distcp
猜你喜欢

Lung CT segmentation challenge 2017 dataset download and description

如何通过NFT GO,来简要判断、分析NFT市场?

How to judge and analyze NFT market briefly through NFT go?

Nuxt 路由切换后 asyncData 跨域报错

Boundless dialogue | participate in the live broadcast on July 25 and win the prize

Re6: reading paper licin: a heterogeneous graph based approach for automatic legal stat identification fro

The next stop of data visualization platform | gifts from domestic open source data visualization datart "super iron powder"
![[assembly language practice] solve the unary quadratic equation ax2+bx+c=0 (including source code and process screenshots, parameters can be modified)](/img/5e/782e5c33accc455994aae044970431.png)
[assembly language practice] solve the unary quadratic equation ax2+bx+c=0 (including source code and process screenshots, parameters can be modified)

Foreign lead operation takes one month to collect money, and the sideline still needs it
![[don't bother to strengthen learning] video notes (II) 1. What is Q-learning?](/img/4f/809adc96e30fad03a113acc3df4b61.png)
[don't bother to strengthen learning] video notes (II) 1. What is Q-learning?
随机推荐
Makefile variables and dynamic library static library
Vscode failed to use SSH Remote Connection (and a collection of other problems)
[example] v-contextmenu right click menu component
What is the component customization event we are talking about?
[Luogu p5410] [template] extend KMP (Z function) (string)
S2b2b system standardizes the ordering and purchasing process and upgrades the supply chain system of household building materials industry
C#/VB. Net: convert word or EXCEL documents to text
Promise basic summary
DSP development, using CCS software to establish engineering and burning
CodeBlocks shortcut key operation Xiaoquan
来阿里一年后我迎来了第一次工作变动....
Introduction to common ansible modules
Spark Learning: Spark implementation of distcp
Firewall off and on command
[don't bother with reinforcement learning] video notes (I) 1. What is reinforcement learning?
[leetcode] 31. Next arrangement
[don't bother to strengthen learning] video notes (IV) 1. What is dqn?
Spark Learning: implement compact table command
dp最长公共子序列详细版本(LCS)
JS locate Daquan to get the brother, parent and child elements of the node, including robot instances