liveBook · Manning

Thread pool

As explained in .NET in Action, Second Edition

A thread pool is a managed collection of reusable worker threads that execute queued work items.

A thread pool supplies reusable worker threads for queued tasks. In a C# asynchronous search, tasks are queued and workers from the .NET thread pool are assigned to execute them. The application does not create a separate thread for every comic it checks. section 4.4

The thread pool is only part of the concurrency picture. HttpClient uses a separate connection pool to manage how many HTTP calls execute simultaneously. Together, these mechanisms help a search across more than 2,600 comics avoid exhausting threads or network sockets. section 4.4

Asynchronous comic search

The search creates a Task for each comic number, then waits for the checks to finish with Task.WhenAll. In the reported tests, the asynchronous search took about 1.5 seconds, compared with more than 30 seconds synchronously; that improvement is not attributed to the thread pool alone. section 4.4

How .NET in Action, Second Edition covers it

How deep it goes
Describes task queuing and worker assignment, but does not explain thread-pool configuration or scheduling internals.
Examples
Uses a search across more than 2,600 comics to illustrate queued tasks and bounded HTTP connections.
What it assumes
Assumes familiarity with C# asynchronous methods and Tasks; explains the pool’s role without teaching synchronization from scratch.
What you can do after
Evaluate/understand why creating many asynchronous search tasks need not exhaust threads or network sockets.
How it connects
Connects the thread pool to Tasks, asynchronous programming, HttpClient connection pooling, and Task.WhenAll.

Also explained in

Compare how 10 books explain thread pool →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.