Reputation: 1039
In .NET Core, let's say we have a web API endpoint which triggers an async/await
operation because there is some I/O work to be done.
Since we're using async/await
, the thread that handles this first request is freed up when I/O work starts.
What if that I/O work takes some time, all other threads are busy(thread pool is full) and a new request comes ? Is it possible for the freed up thread which normally waits for the I/O operation, to pickup work for the new request ?
Upvotes: 1
Views: 1817
Reputation: 456677
Since we're using async/await, the thread that handles this first request is freed up when I/O work starts.
Yes. Once the top-level handler does an await
, that request thread is returned to the thread pool.
What if that I/O work takes some time, all other threads are busy(thread pool is full) and a new request comes ?
If all the request threads are busy, then the request sits in a queue waiting for a free thread.
Is it possible for the freed up thread which normally waits for the I/O operation, to pickup work for the new request ?
It's not clear what you mean by this "thread which normally waits for the I/O operation". The I/O operation was asynchronous, so the request thread has been returned to the thread pool, and there is no thread waiting for the I/O operation.
You might find this article helpful; the details do not apply to ASP.NET Core, but the general concepts do (synchronous vs asynchronous requests, threads "doing" I/O, and thread pool vs async).
Upvotes: 3