(如何)TPL 使用(CLR)线程池?
我目前正在研究任务并行库,我在某处读到 TPL 实际上使用了 CLR 级别的线程池机制。我找不到任何文章证实这一信息。我知道,TPL 每个线程都有任务队列,并使用一些特殊的工作窃取算法来进行平衡。据我所知,它为每个处理器创建一个线程。从.NET 4开始,线程池开始使用TPL的任务对象
。我无法理解TPL如何使用线程池。线程池模式指出,工作项排队,线程池中的空闲线程从该队列中获取一个。然而,TPL 将项目(任务)存储到线程队列中,并且在需要时进行工作窃取......因此,完全不同。我的错误在哪里?
额外问题:由于这是我的第一个 Stack Overflow 问题,我不确定它是否合适。是吗?
I am currently researching Task Parallel Library and I read somewhere that TPL actually uses thread pool mechanism from CLR-Level. I couldn't find any article confirming this information. I know, TPL has task queues for each thread and uses some special work-stealing algorithm for balancing. As far as I know, it creates one thread for each processor. Thread pools started to use task objects of TPL since .NET 4.
I can not understand how TPL uses the thread pool. Thread-Pool pattern states, the work items are queued and the free threads in thread pool takes one from this queue. TPL however store the items (tasks) to queues of threads and work-stealing works if needed... Thus, quite differently. Where is my mistake?
extra question: As this was my first Stack Overflow question, I am not sure if it was suitable. Is it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 TPL 中,
TaskScheduler
负责用于实际排队任务以供执行。 默认调度程序将使用线程池 - 但我相信它是新的线程池实现,它实际上完成了工作窃取的聪明才智。Daniel Moth 有一个 博客文章,其中包含一些您可能会觉得有用的更多详细信息。
In TPL, a
TaskScheduler
is responsible for actually queuing the tasks up for execution. The Default scheduler will use the thread-pool - but I believe it's the new thread pool implementation which actually does the work-stealing cleverness.Daniel Moth has a blog post with some more details which you may find useful.