(How) Does TPL use (CLR) Thread Pool?

2020-02-28 02:15发布

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?

1条回答
Animai°情兽
2楼-- · 2020-02-28 02:42

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.

查看更多
登录 后发表回答