当前位置:网站首页>Thread + thread problem record
Thread + thread problem record
2022-06-25 08:06:00 【qq_ forty-two million eight hundred and sixty-three thousand ni】
This paper records c++ Threads and issues .
List of articles
Thread programming implementation method
windows
3 Kind of
----win32 library
----c++ Runtime
----MFC Class library
linux
2 Kind of
----posix Thread library
----c++11 Thread class library
The relationship between threads
The main thread can create other threads ; Other threads can also create threads ; Threads are equal .
windows
Other threads are descendants of the main thread ,main sign out , Then all descendant threads exit .
linux
Add
guardian Non Guardian
guardian / Non daemon threads only represent the difference between the purposes of threads .
See equality for the above threads . hypothesis n Threads ,n=7. Then the program ( That's the process ) The exit time is equal to the longest thread . That is to say 6 After the threads are executed , The process does not exit , Wait for the seventh thread to finish executing before exiting .
However, such a thread usage scenario cannot be satisfied .
for example 6 Threads execute users , A thread database . So the others are 6 Threads execute on behalf of the user ( process ) Should exit . However, because the thread database cannot determine this, the process cannot exit .
So there are differences between threads . But this belongs to the category of use .
The flag bit can be set to 1 To distinguish
This flag bit is daemon, Guardian .
In terms of usage scenarios, when 6 A thread can represent a process , The seventh one needs to be set daemon. So it is also called user ( The front desk ) And non users ( backstage ) Threads .
Thread to exit
There should be only one way for a thread to exit, that is, the thread function return 0, meanwhile new Memory needs delete.
Just follow main equally . After all, they are all threaded functions .
Thread communication
event
lock
Semaphore
Exclusive access
Threads Concurrent
Multiple threads in the same process usually do different jobs , Can achieve parallel Handle , Avoid a long time occupation of a task CPU Time .
For example, a thread is responsible for sending and receiving data through the network , Another thread does the required computation , The third thread does file input and output , When one of them For some reason Blocking after ( For example, the thread that sends and receives data through the network waits for the other party to send data ), Other threads can still execute without being blocked .
When the number of threads is more than the processor of the computer (CPU) In number , To run all these threads , The operating system is Every Independent Thread scheduling some CPU Time , Operating system to Rotation mode provides time slices to threads , This gives a false impression , It seems that these threads are running at the same time .
The problem record
main Function and thread function return to who
main Exit in the end does not affect
边栏推荐
- Vscode is good, but I won't use it again
- Can bus working condition and signal quality "physical examination"
- [red flag Cup] Supplementary questions
- Authority design of SaaS system based on RBAC
- Dietary intervention reduces cancer treatment-related symptoms and toxicity
- Electronics: Lesson 010 - Experiment 9: time and capacitors
- 黑点==白点(MST)
- RMQ interval maximum subscript query, interval maximum
- @The difference between resource and @autowired annotation, why recommend @resource?
- TCP MIN_RTO 辩证考
猜你喜欢

c#磁盘驱动器及文件夹还有文件类的操作

FM信号、调制信号和载波

Electronics: Lesson 012 - Experiment 13: barbecue LED

C # set up FTP server and realize file uploading and downloading

Electronics: Lesson 013 - Experiment 14: Wearable pulsed luminaries

力扣 272. 最接近的二叉搜索树值 II 递归

Invalid Navicat scheduled task

Can bus working condition and signal quality "physical examination"

Anaconda based module installation and precautions

Electronics: Lesson 012 - Experiment 11: light and sound
随机推荐
CVPR 2022 Oral 2D图像秒变逼真3D物体
C # set up FTP server and realize file uploading and downloading
剑指offer刷题(简单等级)
c#搭建ftp服务器并实现文件上传和下载
TCP 加速小记
Electronics: Lesson 011 - experiment 10: transistor switches
【Unexpected token o in JSON at position 1出错原因及解决方法】
TCP MIN_RTO 辩证考
Atlas conference vulnerability analysis collection
Can bus working condition and signal quality "physical examination"
Startup, shutdown and restart of Oracle and MySQL on Linux
共话云原生数据库的未来
Atlas conflict Remote Code Execution Vulnerability (cve-2022-26134 vulnerability analysis and protection
Matlab代码格式一键美化神器
Est - il sûr d'ouvrir un compte d'actions maintenant via le lien d'ouverture de compte coiffé?
2021ICPC网络赛第一场
静态网页服务器
将数据导入到MATLAB
三台西门子消防主机FC18配套CAN光端机进行光纤冗余环网组网测试
PHP array function Encyclopedia