当前位置:网站首页>How to make the main thread wait for the sub thread to execute before executing
How to make the main thread wait for the sub thread to execute before executing
2022-06-26 06:24:00 【It's very quiet】
Summarize the three methods :
(1)join Method , Direct each thread to join Just go in .
(2)countdownlatch, Internally, a counting operation is maintained , adopt cas The algorithm guarantees the atomicity of the operation , When the thread has finished executing , call countDown() Method , Subtract one from the count , Main thread call countdownlatch Object's await() Method , Suspends the current thread , until countdownlatch The count of objects is 0, Main thread execution .
(3) Something like a barrier , When the sub thread is finished , call CyclicBarrier Object's await() Method , Until a specified number of threads reach the barrier , Will continue to execute the main thread . Compare each child thread to && A condition of a symbol , Then only when all the conditions are met , To execute the main thread .
边栏推荐
- Zotero使用之自定义参考文献格式
- Understanding of nil in go language
- Experience the new features of Milvus 2.0 together
- How to design a good technical scheme
- Alarm operation and Maintenance Center | build an efficient and accurate alarm collaborative processing system
- Message queue - message transaction management comparison
- 去哪儿网BI平台建设演进史
- 视图简析
- Message queuing - omnidirectional comparison
- Mysql delete in 不走索引的
猜你喜欢

Several promotion routines of data governance

如何设计好的技术方案

Underlying principle of MySQL index

GoF23—抽象工厂模式

Mysql delete in 不走索引的

Self attention and multi head self attention (MSA) in transformer
Customer Stories | Netease spring breeze: the "spring breeze" of the fun industry, reaching out to all areas through in-depth interaction

GoF23—原型模式

Prometheus和Zabbix的对比

去哪儿网BI平台建设演进史
随机推荐
如何让主线程等待子线程执行完毕后再执行
打印数字的位信息
TS泛型在函数、接口、类中使用介绍
PyTorch混合精度原理及如何开启该方法
Introduction to canal deployment, principle and use
Five solutions across domains
消息队列-全方位对比
同步通信和异步通信的区别以及优缺点
Unsatisfied dependency expressed through field ‘baseMapper‘; nested exceptio
Keepalived to achieve high service availability
Data visualization practice: Data Visualization
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
DPDK——TCP/UDP协议栈服务端实现(二)
canal部署、原理和使用介绍
typescript的type
Load balancer does not have available server for client: userService问题解决
China micro cultivator market trend report, technical dynamic innovation and market forecast
低代码实时数仓构建系统的设计与实践
Efk upgrade to Clickhouse log storage practice
Design and practice of low code real-time data warehouse construction system