当前位置:网站首页>如何让主线程等待子线程执行完毕后再执行
如何让主线程等待子线程执行完毕后再执行
2022-06-26 06:05:00 【明明就很安静】
总结三个方法:
(1)join方法,直接将每个线程都join进去即可。
(2)countdownlatch,内部维持一个计数操作,通过cas算法保证操作的原子性,当线程执行完之后,调用countDown()方法,将计数减一,主线程调用countdownlatch对象的await()方法,将当前线程挂起,直到countdownlatch对象的计数为0,主线程执行。
(3)类似屏障的东西,当子线程执行完之后,调用CyclicBarrier对象的await()方法,直到指定数量的线程到达屏障之后,才会继续执行主线程。把每一个子线程比作&&符号的一个条件,那么只有到所有条件都满足时,才会执行主线程。
边栏推荐
- 解决在win10下cmder无法使用find命令
- tf. nn. top_ k()
- Cython入门
- Use the fast proxy to build your own proxy pool (mom doesn't have to worry about IP being blocked anymore)
- How to select and build a real-time data warehouse scheme
- Test depends on abstraction and does not depend on concrete
- Force buckle 875 Coco, who likes bananas
- Getting started with Python
- String class learning
- How to use the tablet as the second extended screen of the PC
猜你喜欢

MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

Redis underlying data structure

【Spark】Spark SQL 字段血缘如何实现

EFK昇級到ClickHouse的日志存儲實戰

Deeply uncover Ali (ant financial) technical interview process with preliminary preparation and learning direction
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast

Playing RTSP streaming video on Web pages (webrtc)

PyTorch使用多GPU并行训练及其原理和注意事项

Import / export function implementation

Test depends on abstraction and does not depend on concrete
随机推荐
【群内问题学期汇总】初学者的部分参考问题
Interface oriented programming
解决在win10下cmder无法使用find命令
Logstash——使用throttle过滤器向钉钉发送预警消息
numpy.random.choice
NPM private server problem of peanut shell intranet penetration mapping
numpy. log
Kolla ansible deploy openstack Yoga version
Library management system
Comparison between Prometheus and ZABBIX
Detailed explanation of serial port communication principle 232, 422, 485
MySQL 索引底层原理
Logstash - logstash pushes data to redis
Logstash——Logstash向Email发送告警邮件
数据可视化实战:数据可视化
How to design a good technical scheme
5 minutes to learn regular expressions
Logstash——Logstash将数据推送至Redis
实时数仓方案如何选型和构建
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications