当前位置:网站首页>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 .
边栏推荐
- Easy to understand: basic knowledge of MOS tube
- 使用 Web API 上传和下载多个文件
- QT actual combat case (53) -- using qdrag to realize the drag puzzle function
- [datawhale202207] reinforcement learning: strategy gradient and near end strategy optimization
- [daily question 1] 1184. Distance between bus stops
- Qt实战案例(53)——利用QDrag实现拖拽拼图功能
- 长安链双花交易防范策略
- Shell run command
- 分层强化学习综述:Hierarchical reinforcement learning: A comprehensive survey
- [daily question] sword finger offer II 115. reconstruction sequence
猜你喜欢

Keilc51 usage details (III)

【剑指Offer】模拟实现atoi

YOLOv7模型推理和训练自己的数据集

The code of Keil and Si compiler is not aligned??

Can communication test based on STM32: turn the globe

Hierarchical reinforcement learning: a comprehensive survey

Cointegraph wrote: relying on the largest Dao usdd to become the most reliable stable currency

代码中的软件工程:正则表达式十步通关

Download and run the C open source control metroframework demo project

Rongyun launched a real-time community solution and launched "advanced players" for vertical interest social networking
随机推荐
[C language] document processing and operation
[daily question] sword finger offer II 115. reconstruction sequence
Baidu xirang's first yuan universe auction ended, and Chen Danqing's six printmaking works were all sold!
Shell run command
A little consideration of strategic mode
The code spell checker plug-in avoids some specific vocabulary errors "XXX": unknown word.cspell
【C】 Program environment and pretreatment
Easy to use code statistics tool
Quick sort code implementation
【每日一题】剑指 Offer II 115. 重建序列
Easy to understand: basic knowledge of MOS tube
Discuss the important factors that affect the success or failure of automated testing
Rongyun launched a real-time community solution and launched "advanced players" for vertical interest social networking
不只是日志收集,项目监控工具Sentry的安装、配置、使用
共模电感听过很多次,但是什么原理你们真的懂吗?
Common mode inductance has been heard many times, but what principle do you really understand?
Argocd user management, RBAC control, script login, APP synchronization
Scientific computing library numpy Foundation & Improvement (Understanding + explanation of important functions)
Robot engineering - teaching quality - how to judge
【剑指Offer】模拟实现atoi