vote buttons
1
1
beginner
0
intermediate
0
advanced

How does the TPL ThreadPool differ from normal thread pool and how do we know which thread pool is getting used?

11-Oct-2014 04:34 UTC
K Bonneau
350

1 Answers

vote buttons
1

The TPL thread pool and the traditional thread pool work in significantly different ways. Any threads invoked using Task Parallel Library use TPL thread pool while thread invoked using QueueUserWorkItem or other traditional methods use the traditional thread pool.

In case of traditional thread pool there exists a single queue for work items which are accessed by each thread in the thread pool when it asks for work. This causes contention as all threads for each core are competing for this shared resource (the work queue). The TPL thread pool was designed to minimize this contention. Instead of having just one queue, TPL thread pool has a queue per logical processor. As there can only be as many physical threads as number of cores, each thread works on it own queue and is virtually contention free.

A concept of work stealing was introduced. If a thread's queue is empty it "steals" work from other thread queues. Work stealing is expensive but it doesn't happen most of the time.


11-Oct-2014 04:45 UTC
K Bonneau
350