当前位置:网站首页>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 .
边栏推荐
- 财务数字化转型
- SQL optimization principles
- [don't bother with reinforcement learning] video notes (I) 2. Summary of reinforcement learning methods
- Firewall off and on command
- SQL 优化原则
- MySQL Basics (I) -- SQL Basics
- Ue5 film and television animation rendering MRQ layered learning notes
- Leetcode94 detailed explanation of middle order traversal of binary tree
- Huawei wireless device security policy configuration command
- Embedded development: Tools - optimizing firmware using DRT
猜你喜欢
![[assembly language practice] (II). Write a program to calculate the value of expression w=v- (x+y+z-51) (including code and process screenshots)](/img/0d/c8042ce5019d7dc5414dde5ebf1e8d.jpg)
[assembly language practice] (II). Write a program to calculate the value of expression w=v- (x+y+z-51) (including code and process screenshots)

What's the difference between testing / developing programmers' professionalism and salted fish? They don't want to be excellent coders?

Opencv learning Day5

Spark Learning: compile spark source code in win10

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

程序的编译与链接
![[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?

Write a simple memo using localstorage

Open source summer interview | learn with problems, Apache dolphin scheduler, Wang Fuzheng

《动手学深度学习》(七) -- 边界框和锚框
随机推荐
Code random notes_ Linked list_ Turn over the linked list in groups of 25K
Aruba learning notes 06 wireless control AC basic configuration (CLI)
js定位大全获取节点的兄弟,父级,子级元素含robot实例
Firewall off and on command
How to improve office efficiency through online collaborative documents
Aruba学习笔记06-无线控制AC基础配置(CLI)
Ansible 常用模块介绍
Vscode failed to use SSH Remote Connection (and a collection of other problems)
ASI-20220222-Implicit PendingIntent
Cess test online line! The first decentralized storage network to provide multiple application scenarios
[don't bother to strengthen learning] video notes (II) 1. What is Q-learning?
SQL optimization principles
Leetcode skimming: dynamic planning 03 (climb stairs with minimum cost)
Lung CT segmentation challenge 2017 dataset download and description
One year after I came to Ali, I ushered in my first job change
Re6:读论文 LeSICiN: A Heterogeneous Graph-based Approach for Automatic Legal Statute Identification fro
[don't bother to strengthen learning] video notes (IV) 2. Dqn realizes maze walking
Will your NFT disappear? Dfinity provides the best solution for NFT storage
JS, the return statement used in the for loop should be placed in the function to terminate the loop, similar to the invalid return problem in break & foreach
Es document CRUD