当前位置:网站首页>C multithreading learning note 3
C multithreading learning note 3
2022-06-10 13:58:00 【HollowKnightZ】
Thread pool ThreadPool
ThreadPool
Thread => One asynchronous task starts one Thread, Proprietary
ThreadPool => To start an asynchronous task, you only need to borrow threads from it , Return after use
ThreadPool How to use
ThreadPool.QueueUserWorkItem((obj) =>
{
var Fun = obj as Func<string>;
Console.WriteLine(" Sub thread :" + Thread.CurrentThread.ManagedThreadId + " context:" + Fun());
}, new Func<string>(() => "hello world"));
Console.WriteLine(" The main thread :" + Thread.CurrentThread.ManagedThreadId);
Console.ReadKey();
ThreadPool And Thread The difference between
10 A mission , use Thread To do it , Need to open 10 individual Thread, If you use ThreadPool To do it , Only need to 10 Tasks are assigned to the thread pool .
Thread The analytic function of is as follows :
~Thread()
{
this.InternalFinalize();
}
From the destructor we can see this.InternalFinalize(); That is to say, after destruction , First in Terminator , The thread is destroyed , But not by GC(Garbage Collection) Recycling , The resources that should be occupied will still be occupied . While using ThreadPool There will be no dead threads , They are initialized by default .
Threads in the thread pool : Worker threads and IO Threads

The worker thread : For general asynchronous tasks , It doesn't involve the network , File these IO operation 【 open Sender call 】
IO Threads : Generally used in documents , The Internet IO On .【CLR call 】
summary
ThreadPool It can be used 8 Threads to solve thread 10 What a thread does , Save space and time .
Time => Notify each managed and unmanaged DLL
Space => teb,osthread structure , Stack
边栏推荐
- 解决VMWareStation安装 tools 时 D:\setup.exe 找不到的问题
- [notes] notes on C language array pointer, structure + two-dimensional array pointer
- 解决win10虚拟机和主机不能互相粘贴复制的问题
- 工作中记录MySQL中的常用函数
- Solve the problem of cross sea high concurrent crash? so easy
- anaconda安装opencv(cv2),在jupyter notebook中使用
- Docker部署一个Redis集群
- Qualcomm has finally begun to develop its own core architecture after learning from the difficulties of assembling chips to maintain its competitive advantage
- IIC总线的主要特点/通信过程/读写过程
- [deep learning 05] cross entropy loss function
猜你喜欢

Flutter Wrap Button bottomNavigationBar学习总结4

What is the p value of a gene?
![[cloud computing] what is the relationship between a multi cloud management platform and a public cloud?](/img/8f/f57da7079979ceaef903255bc25432.png)
[cloud computing] what is the relationship between a multi cloud management platform and a public cloud?

还在说大学排名是笑话?最新规定:世界top50大学可以直接落户上海!

智慧校园安全通道及视频监控解决方案

C#多线程学习笔记一

2022广东省安全员A证第三批(主要负责人)考试练习题及在线模拟考试

焱融看|混合云环境下,如何实现数据湖最优存储解决方案

Gree mobile phone challenge Apple mobile phone? I'm afraid there's nothing else but hard talk
![[operation tutorial] how to correctly use the Hikvision demo tool to configure the channel to go online?](/img/2f/b4d18ac1f030f7678e6f0b59c61291.png)
[operation tutorial] how to correctly use the Hikvision demo tool to configure the channel to go online?
随机推荐
CentOS Linux 已死!Oracle Linux 可能是它的更好替代品
Can qiniu open an account? Can the security of securities companies be directly opened on the app
Snackbar使用详解
Mmdetection adds precision to the evaluation index
大厂面试上午10:00面试,10:09就出来了 ,问的实在是太...
How to deal with the interview for the fresh senior graduates who want to self-study software testing?
Cardview usage and properties
大四应届毕业生,想自学软件测试,如何应对面试?
[C language] pointer function, function pointer and array function
解决跨海高并发崩溃难题?so easy
Implementation of VGA protocol based on FPGA
win10虚拟机下载安装流程
odoo 权限管理(访问权限及记录规则)结合实用,升级角色管理
【解决】每次加载已经训练好的模型,生成的向量会有不同
Record common functions in MySQL at work
Flutter drawer学习总结6
【云计算】多云管理平台和公有云两者之间是啥关系?
Markdown sets the font to red
Kotlin practises. Take login as an example. Anko simply uses it
互联网公司研发效能团队为啥必须独立?何时独立?