当前位置:网站首页>Wei Lai: what is the difference between multithreaded join and detach?
Wei Lai: what is the difference between multithreaded join and detach?
2022-07-25 06:53:00 【A vegetable programmer】
1、 Rendezvous (joinable): In this relationship , The main thread needs to explicitly perform the wait operation , After the child thread ends , The waiting operation of the main thread is completed , The child thread meets the main thread , At this time, the main thread continues to perform the next operation after the wait operation . The main thread must rendezvous with renderable child threads . Call the function of the child thread object inside the thread function of the main thread wait Function implementation , Even if the child thread can finish executing before the main thread , Into the termination state , The rendezvous operation must also be performed , otherwise , The system will never actively destroy threads , The system resources allocated to the thread will never be released .
2、 phase separation (detached): Indicates that the child thread does not need to meet with the main thread , That is, phase separated , In this case , Once the child thread enters the termination state , This method is often used when there are many online processes , Sometimes the main thread is asked to wait one by one for the sub thread to end , Or let the main thread arrange the waiting order for the end of each sub thread , It is difficult or impossible , So when there are many concurrent sub threads , This method is also often used .
At any point in time , Threads are associative (joinable) Or separable (detached), A combinable thread can be recycled and killed by other threads , Before being recycled by other threads , Its memory resources, such as stack , It's not released , contrary , A detached thread cannot be recycled or killed by other threads , Its memory resources are automatically released by the system when it terminates .
The state of thread separation determines how a thread terminates itself , By default , Threads are non detached , In this case , The original thread waits for the created thread to finish , Only when pthread_join When function returns , The thread created is terminated , Release the system resources occupied by yourself , The detached thread is not waiting by other threads , It's over , The thread is terminated , Release system resources now .
边栏推荐
- [C language] program environment and preprocessing
- 长安链Solidity智能合约调用原理分析
- 【愚公系列】2022年7月 Go教学课程 016-运算符之逻辑运算符和其他运算符
- When the graduation season comes, are you ready? What are we going to do
- Rongyun launched a real-time community solution and launched "advanced players" for vertical interest social networking
- 健康打卡每日提醒累了?那就让自动化帮你---HiFlow,应用连接自动化助手
- 【Jailhouse 文章】Base Architectures for virtual-physical computing(2018)
- QT actual combat case (53) -- using qdrag to realize the drag puzzle function
- Analysis of the calling principle of Changan chain solid smart contract
- 蔚来一面:多线程join和detach的区别?
猜你喜欢

【每日一题】1184. 公交站间的距离

What are the hazards of insufficient sleep?

C#开源控件MetroFramework Demo项目下载和运行
![[C language] document processing and operation](/img/d7/3d34401f78399dcd6d571bc0bc84bf.png)
[C language] document processing and operation

健康打卡每日提醒累了?那就让自动化帮你---HiFlow,应用连接自动化助手

C # --metroframework framework calls the metromodernui library and uses it in the toolbar

Easy to understand: basic knowledge of MOS tube

JZ7 rebuild binary tree

Qt实战案例(53)——利用QDrag实现拖拽拼图功能

The code spell checker plug-in avoids some specific vocabulary errors "XXX": unknown word.cspell
随机推荐
Detailed explanation of the difference, working principle and basic structure between NMOS and PMOS
Restrict Su command and sudo mechanism to promote nmap and console command netstat
C # --metroframework framework calls the metromodernui library and uses it in the toolbar
[sword finger offer] analog implementation ATOI
HTX00001_ Keil51 bug encountered in serial port parsing
Analysis of the calling principle of Changan chain solid smart contract
CEPH in hand, I have!
Qt实战案例(53)——利用QDrag实现拖拽拼图功能
150. Evaluation of inverse Polish expression
%d,%s,%c,%x
【transformer】DeiT
如何学习 C 语言?
杜教筛
睡眠不足有哪些危害?
JS data type judgment - Case 6 delicate and elegant judgment of data type
Leetcode 206. reverse linked list I
【剑指Offer】模拟实现atoi
mvc与三层结构终极区别
不只是日志收集,项目监控工具Sentry的安装、配置、使用
【愚公系列】2022年7月 Go教学课程 016-运算符之逻辑运算符和其他运算符