当前位置:网站首页>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
边栏推荐
- Pychart's wonderful setting: copy immediately after canceling the comment and bring #
- 【补题】2021牛客暑期多校训练营1-3
- How to resize an image in C #
- 共话云原生数据库的未来
- 取消word文档中某些页面的页眉
- Luogu p5994 [pa2014]kuglarz (XOR thinking +mst)
- 50. pow (x, n) - fast power
- Pycharm的奇葩设定:取消注释后立马复制会带上#
- CVPR 2022 Oral 2D图像秒变逼真3D物体
- 电子学:第014课——实验 15:防入侵报警器(第一部分)
猜你喜欢

Three Siemens fire-fighting hosts fc18 are equipped with can optical transceiver for optical fiber redundant ring network networking test

将数据导入到MATLAB

CVPR 2022 Oral 2D图像秒变逼真3D物体

Allgero reports an error: program has encoded a problem and must exit The design will be saved as a . SAV file

50 pieces of professional knowledge of Product Manager (IV) - from problem to ability improvement: amdgf model tool

將數據導入到MATLAB

使用报文和波形记录分析仪RoyalScope的帧统计功能排查CAN总线偶发性故障

Electronics: Lesson 013 - Experiment 14: Wearable pulsed luminaries

c#搭建ftp服务器并实现文件上传和下载

电子学:第011课——实验 10:晶体管开关
随机推荐
ffmpeg+SDL2实现音频播放
洛谷P3313 [SDOI2014]旅行(树链+边权转点权)
Import data into Matlab
Solving some interesting problems with recurrence of function
Matlab code format one click beautification artifact
Anaconda based module installation and precautions
2021ICPC网络赛第一场
电子学:第012课——实验 13:烧烤 LED
Allgero reports an error: program has encoded a problem and must exit The design will be saved as a . SAV file
云计算考试版本1.0
Luogu p2839 [national training team]middle (two points + chairman tree + interval merging)
Black dot = = white dot (MST)
Ubuntu18下登录mysql 5.7设置root密码
[red flag Cup] Supplementary questions
Atlas conference vulnerability analysis collection
企业全面云化的时代——云数据库的未来
c#搭建ftp服务器并实现文件上传和下载
Use the frame statistics function of the message and waveform recording analyzer royalscope to troubleshoot the accidental faults of the CAN bus
不怕百战失利,就怕灰心丧气
现在通过开户经理发的开户链接股票开户安全吗?