当前位置:网站首页>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
边栏推荐
- 洛谷P3313 [SDOI2014]旅行(树链+边权转点权)
- Electronics: Lesson 012 - Experiment 11: light and sound
- 初体验完全托管型图数据库 Amazon Neptune
- Set the textalign property of the label control in C to control the method of text centering
- Luogu p3313 [sdoi2014] travel (tree chain + edge weight transfer point weight)
- Luogu p1073 [noip2009 improvement group] optimal trade (layered diagram + shortest path)
- 基于Anaconda的模块安装与注意事项
- 共话云原生数据库的未来
- 电子学:第010课——实验 8:继电振荡器
- Apache CouchDB 代码执行漏洞(CVE-2022-24706 )批量POC
猜你喜欢

三台西门子消防主机FC18配套CAN光端机进行光纤冗余环网组网测试

Can bus working condition and signal quality "physical examination"

Vscode is good, but I won't use it again

Importer des données dans MATLAB

自制坡道,可是真的很香

【论文学习】《VQMIVC》

电子学:第013课——实验 14:可穿戴的脉冲发光体

To understand the difference between Gram-positive and Gram-negative bacteria and the difference in pathogenicity

静态网页服务器

c#ColorDialog更改文本颜色和FontDialog更改文本字体的使用示例
随机推荐
环网冗余式CAN/光纤转换器的CAN光端机在消防火灾联网报警系统中的应用
剑指offer刷题(中等等级)
Luogu p5994 [pa2014]kuglarz (XOR thinking +mst)
云计算考试版本1.0
Electronics: Lesson 010 - Experiment 9: time and capacitors
网络模型——OSI模型与TCP/IP模型
使用报文和波形记录分析仪RoyalScope的帧统计功能排查CAN总线偶发性故障
深度学习系列48:DeepFaker
50. pow (x, n) - fast power
Ph中和过程建模
飞机引气系统的建模与故障仿真
c#磁盘驱动器及文件夹还有文件类的操作
电子学:第012课——实验 11:光和声
Force deduction 76 questions, minimum covering string
2265. number of nodes with statistical value equal to the average value of subtree
Pychart's wonderful setting: copy immediately after canceling the comment and bring #
Ubuntu18下登录mysql 5.7设置root密码
图像超分综述:超长文一网打尽图像超分的前世今生 (附核心代码)
电子学:第012课——实验 13:烧烤 LED
共话云原生数据库的未来